158月 2017

0

2440

0

QT QString 设置浮点数 小数点位数

Qt by xfire

QString QString::number(double n, char format = ‘g’, int precision = 6)

Returns a string equivalent of the number n, formatted according to the specified format and precision. See Argument Formats for details.

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

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).

 

举个栗子

QString::number(number, 'f', 3);

返回小数点后三位数值

微信扫描二维码
为老wu 打个赏
pay_weixin
金额随意 快来“打”我呀 老wu要买六味地黄丸补补~~

原创文章,转载请注明: 转载自 吴川斌的博客 http://www.mr-wu.cn/

本文链接地址: QT QString 设置浮点数 小数点位数 http://www.mr-wu.cn/qt-qstring-argument-formats/

Comments (0)