[Solved] Difference between QString::number() & QString::setNum()?
-
Hi,
I want to convert a double variable to a QString. I want to have a very strict control over the precision & accuracy. A faster method would be convenient. I have found these 2 functions : QString::number() & QString::setNum(). Both perform the conversion from double to a QString with user defined precision & formatting. So I wanted to know what is the difference between these 2 methods. There must be some difference that is why they have provided these 2 functions, right?
Thank You. -
the one is static the other is not ;)
-
Seriously is that the only difference?
lol -
[quote author="CAD_coding" date="1367559446"]Seriously is that the only difference?
lol[/quote]Yes :) Conceptually, they are quite different.QString::number() creates a new string and returns it. It doesn't delete/change existing data. (Well, if you assign the return value to an old variable, then the old data is replaced... but that's due to the assignment operator, not QString::number()).
QString::setNum() takes an existing string replaces its contents. The old data is gone.
-
ok. Got it. :)
-
[quote author="mickey" date="1367560798"]Can you tell me functions to convert string to double?[/quote]
did you even look once at the "docs":http://qt-project.org/doc/qt-4.8/qstring.html#toDouble?!