Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use void QTextStream::setRealNumberNotation



  • Hi,

    I need to use void QTextStream::setRealNumberNotation(RealNumberNotat ion notation). I looked at so-called Docs for it, but there is no example for beginners! (It's here:)

    For example:

    QString ss;
    QTextStream (&ss);
     // here to use it
    

    How to use it please?


  • Qt Champions 2017

    Try

    ss.setRealNumberNotation(QTextStream::ScientificNotation) or ss.setRealNumberNotation(QTextStream::FixedNotation) or
    ss.setRealNumberNotation(QTextStream::SmartNotation)



  • Thank you. Please have a look at these:

    QString s;
    QTextStream ss(&s);
    ss.setRealNumberNotation(QTextStream::SmartNotation);
    ss << 1000000;
    result_box -> setText(s);
    

    Here the result is: 1000000
    But in this one:

    QString s;
    double d = 1000000;
    QTextStream ss(&s);
    ss.setRealNumberNotation(QTextStream::SmartNotation);
    ss << d;
    result_box -> setText(s);
    

    The result is: 1e+06 !!!

    Why? And how to solve it please?


  • Lifetime Qt Champion

    Hi,

    You're not using the same types in both code sample. Once you send an integer and next a double. setRealNumberNotation affects float and double, not integers.



  • OK, thanks.


  • Lifetime Qt Champion

    You're welcome !

    If that answers your question then please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)


Log in to reply