我的程序中有以下几行代码:
long double endJD = 2456541.41563;
QString tempString = "";
tempString.append(QString::number((double) endJD));
QMessageBox msgBox;
msgBox.setText(tempString);
msgBox.exec();
它运行得很好,但是输出是: 2.45654e+06,那么我怎么才能得到想要的小数位的输出数呢?我可以删除一些小数,但我希望在输出中至少有两个小数点。
发布于 2013-09-06 06:03:49
您需要将格式说明符传递给QString::number。
tempString.append(QString::number((double) endJD, 'f'));
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
如果不指定,它将默认为"g“。
https://stackoverflow.com/questions/18646659
复制相似问题