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