Convert a double to a QString

后端 未结 5 702
北荒
北荒 2021-02-02 05:39

I am writing a program in QT. I want to convert a double into a Qstring in C++.

5条回答
  •  遥遥无期
    2021-02-02 05:58

    You can use arg(), as follow:

    double dbl = 0.25874601;
    QString str = QString("%1").arg(dbl);
    

    This overcomes the problem of: "Fixed precision" at the other functions like: setNum() and number(), which will generate random numbers to complete the defined precision

提交回复
热议问题