Rahul Tungar
Rahul Tungar

Reputation: 7

Qt-append deminal part of float number to long varibale

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

Answers (1)

Jeet
Jeet

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

Format Meaning

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

Related Questions