Vij*_*y13 2 c++ qt number-formatting
我的程序中有以下代码行:
long double endJD = 2456541.41563;
QString tempString = "";
tempString.append(QString::number((double) endJD));
QMessageBox msgBox;
msgBox.setText(tempString);
msgBox.exec();
Run Code Online (Sandbox Code Playgroud)
它运行良好,但输出为:2.45654e+06,那么如何获得所需小数位的输出数字?我同意删除一些小数,但我希望输出中至少有两位小数。
您需要将格式说明符传递给 QString::number。
tempString.append(QString::number((double) endJD, 'f'));
Run Code Online (Sandbox Code Playgroud)
Qt 文档中提供的格式,
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
Run Code Online (Sandbox Code Playgroud)
如果您不指定,它将默认为“g”。
| 归档时间: |
|
| 查看次数: |
3000 次 |
| 最近记录: |