• 8072阅读
  • 3回复

QTextStream的float小数点位数怎么设置? [复制链接]

上一主题 下一主题
离线bluetornado
 
只看楼主 正序阅读 楼主  发表于: 2009-08-27
我想设置小数点后的数值位数为3位,不知道应该怎么设置?
离线dbzhang800

只看该作者 3楼 发表于: 2009-08-27
引用第2楼bluetornado于2009-08-27 12:07发表的  :
setRealNumberPrecision是设置所有数的个数,而不是小数点后数的个数

这是你单方面的想法吧? 还是你求证过或者自己试过后结论确实如此?


难道QTextStream中没有类似于C中的".3%f"这种东东吗?


即使你不熟悉 QTextStream ,QString 应该比较熟悉吧,先把你的浮点数 转成 QString 而后再用 QTextStream 总该没问题了
离线bluetornado
只看该作者 2楼 发表于: 2009-08-27
setRealNumberNotatiion是设置符号的
setRealNumberPrecision是设置所有数的个数,而不是小数点后数的个数
setNumberFalgs更没有关系
难道QTextStream中没有类似于C中的".3%f"这种东东吗?
离线dbzhang800

只看该作者 1楼 发表于: 2009-08-27
QTextStream & QTextStream::operator<< ( float f )

Writes the real number f to the stream, then returns a reference to the QTextStream. By default, QTextStream stores it using SmartNotation, with up to 6 digits of precision. You can change the textual representation QTextStream will use for real numbers by calling setRealNumberNotation(), setRealNumberPrecision() and setNumberFlags().

See also setFieldWidth(), setRealNumberNotation(), setRealNumberPrecision(), and setNumberFlags().
快速回复
限100 字节
 
上一个 下一个