View Full Version : comma as decimal seperator

26th August 2015, 20:51
Hi, i got the problem with result when inputing numbers in 2 lineedits like:

first line edit: 12,7
secound line edit: 7,2

and expect sum result in third one: 19,9 , but i get nothing becouse of comma as seperator. if i put numbers like 12.7 and 7.2 i get 19.9

soo i wonder is there any solution to that... i rly don't care if result is 19,9 or 19.9 i just whanna make my qt calculate with dot and/or comma as decimal seperator...

Thanks, and i hope i explain my problem well

26th August 2015, 21:16

if you take the input from a line edit you get a string, that needs to get translated into a double/float number. You can do that translation by yourself writing a suitable parsing function or you may use a locale with comma as decimal separator and apply QLocale::toDouble() to your string.
An example:

QLocale l(QLocale::German);
double f = l.toDouble("12,2");
std::cout << f << std::endl;
See http://doc.qt.io/qt-5.4/qlocale.html

Best regards

26th August 2015, 22:35
thanks!! big thanks!!

i read that link few times before posting on forum and couldn't get it, but i understand it now from your explanation!

it works perfectly!