21,489
社区成员
发帖
与我相关
我的任务
分享
QString QString::number(double n, char format = 'g', int precision = 6) [static]
Returns a string equivalent of the number n, formatted according to the specified format and precision. See Argument Formats for details.
Unlike QLocale::toString(), this function does not honor the user's locale settings.
See also setNum() and QLocale::toString().
Argument Formats
In member functions where an argument format can be specified (e.g., arg(), number()), the argument format can be one of the following:
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
A precision is also specified with the argument format. For the 'e', 'E', and 'f' formats, the precision represents the number of digits after the decimal point. For the 'g' and 'G' formats, the precision represents the maximum number of significant digits (trailing zeroes are omitted).
关键是第二个参数应该传什么,如果是默认的g是得不到你要的结果的,第三个参数是你想要保留的小数点后面的位数