Reputation: 7
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?
Upvotes: 0
Views: 74
Reputation: 1046
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
Upvotes: 2