浮点数转字符串的问题
我现在用QString::number(double)转,但是有个问题,比如输入100.00,输出的就是100,我想强制保留小数点后两位,应该用什么函数?
[解决办法]
QString::number(yourDouble, '.', 2);
[解决办法]
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:
FormatMeaning
eformat as [-]9.9e[+
[解决办法]
-]999
Eformat as [-]9.9E[+
[解决办法]
-]999
fformat as [-]9.9
guse e or f format, whichever is the most concise
Guse 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).