I have unsigned long a=999999999;
and float b=0.123456;
and i want to have result in QString
as 999999999.123456
what is best way to do this?
Asked
Active
Viewed 69 times
0

demonplus
- 5,613
- 12
- 49
- 68

Rahul Tungar
- 7
- 2
1 Answers
2
Below is one of the way. (but i don't know whether this way is best or not).
#include <QCoreApplication>
#include <QString>
#include <iostream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
unsigned long ulng=999999999UL;
float flt=0.123456F;
//format 'f' meaning given below
QString str = QString::number((double)ulng+flt,'f');
std::cout << "Total = " << str.toStdString() << std::endl;
return a.exec();
}
Output:
Total = 999999999.123456
e format as [-]9.9e[+|-]999
E format as [-]9.9E[+|-]999
f format as [-]9.9
g use e or f format, whichever is the most concise
G use E or f format, whichever is the most concise

Jeet
- 1,006
- 1
- 14
- 25