QT中如何格式化double类型的数
如题,QT中得到一个double类型的数,我想设置它小数点后的位数,显示在line_Edit控件中,请问怎么设置啊?...
如题,QT中得到一个double类型的数,我想设置它小数点后的位数,显示在line_Edit控件中,请问怎么设置啊?
展开
1个回答
展开全部
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().
double a=3.567;
editLine->setText(QString::number(a,'g',1));
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().
double a=3.567;
editLine->setText(QString::number(a,'g',1));
追问
请问QString::number()中间的字符参数都有什么意思啊,我看英文的帮助文档没有看懂...
追答
第一个参数是double类型的数字,第二个参数是数字的格式,比如科学计数法或者什么,直接用默认的'g'就行。最后是小数点后的位数。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询