QString to Double conversion problem
-
I'm a new bie in qt. I have a problem while converting a string value to double. My string value is
@QString str = 100.94519;
double value = str.toDouble();
@My Output while converting it to double is 100.95.
The problem is the double value is converting to 2 decimals. But i want the same string value to be converted as a double value. How can i convert a string value to a double value? -
Hi,
You should have a look to "QString documentation":http://qt-project.org/doc/qt-4.8/qstring.html#number-2 and use the method QString::number.
Regards,
Jonathan -
[quote author="maisoui" date="1379937149"]Hi,
You should have a look to "QString documentation":http://qt-project.org/doc/qt-4.8/qstring.html#number-2 and use the method QString::number.
Regards,
Jonathan
[/quote]While you should read the post thoroughly :P The OP is asking for a conversion from QString to double, not the other way around.
-
Raagini try with QLocale::toDouble().
-
Are you sure the value in your string is correct? That's why I talked about QString::number.
For me this line is not correct : QString str = 100.94519; (Which version of Qt do you use?)
Regards
-
Ah right, maisoui my bad, apologies.
However, I suspect this is just a quick example and the actual code in Raagini's project is different.