qreal如何转换到QString

qiuzhiguaniu 2009-08-18 03:45:37
错误: 对成员‘toString’的请求出现在‘((QBBall*)this)->QBBall::position.QPointF::y()’中,而后者具有非类类型‘qreal’
该如何转化呢,想了半天也没找到方法。
...全文
1672 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ilovejunk 2012-08-26
  • 打赏
  • 举报
回复
谢谢,太好了
windy9602 2011-05-27
  • 打赏
  • 举报
回复
正好遇到类似的问题
看看一楼的解释
qiuzhiguaniu 2009-08-18
  • 打赏
  • 举报
回复
谢谢,看懂了
goodname 2009-08-18
  • 打赏
  • 举报
回复
也可以

QString QString::arg ( double a, int fieldWidth = 0, char format = 'g', int precision = -1, const QChar & fillChar = QLatin1Char( ' ' ) ) const
This is an overloaded member function, provided for convenience.
Argument a is formatted according to the specified format, which is 'g' by default and can be any 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

With 'e', 'E', and 'f', precision is the number of digits after the decimal point. With 'g' and 'G', precision is the maximum number of significant digits (trailing zeroes are omitted).
double d = 12.34;
QString str = QString("delta: %1").arg(d, 0, 'E', 3);
// str == "delta: 1.234E+01"
The '%' can be followed by an 'L', in which case the sequence is replaced with a localized representation of a. The conversion uses the default locale, set by QLocale::setDefaultLocale(). If no default locale was specified, the "C" locale is used.
See also QLocale::toString().
goodname 2009-08-18
  • 打赏
  • 举报
回复 1
typedef qreal
Typedef for double on all platforms except for those using CPUs with ARM architectures. On ARM-based platforms, qreal is a typedef for float for performance reasons.

所以你可以使用
QString QString::number ( double n, char format = 'g', int precision = 6 ) [static]
This is an overloaded member function, provided for convenience.
Returns a string equivalent of the number n, formatted according to the specified format and precision. The format can be 'f', 'F', 'e', 'E', 'g' or 'G' (see the arg() function documentation for an explanation of the formats).
Unlike QLocale::toString(), this function does not honor the user's locale settings.
See also setNum() and QLocale::toString().

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧