Let's say that I have a double number: 1679616. When I try to set text to label, the number is shown as 1.67962e+06. Is there a way so that the number can be shown as it is without exponential format?
If I use: QString::number(result, 'f', 2) to cast the number to string, everything is OK, but what if the number has more than two digits after that point? I know that I can set it to be 10 for example, but you know that this is not the right thing that I want to do. I want if the number is 82348.12323 to be shown as it is. If it is 234.2, I want just one number after the point.
The following examples work pretty well for me:
double a1 = 82348.12323;
double a2 = 234.2;
QString s1 = QString::number(a1, 'g', 10);
QString s2 = QString::number(a2, 'g', 10);
qDebug() << "s1:" << s1;
qDebug() << "s2:" << s2;
Output:
s1: "82348.12323"
s2: "234.2"
More information on the format argument can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With