|
double QString::toDouble(bool * ok = 0) const
Returns the string converted to a double value.
Returns 0.0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
QString str = "1234.56";
double val = str.toDouble(); // val == 1234.56
Warning: The QString content may only contain valid numerical characters which includes the plus/minus sign, the characters g and e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.
bool ok;
double d;
d = QString( "1234.56e-02" ).toDouble(&ok); // ok == true, d == 12.3456
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toDouble()
d = QString( "1234,56" ).toDouble(&ok); // ok == false
d = QString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56
For historical reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble().
d = QString( "1,234,567.89" ).toDouble(&ok); // ok == false
d = QString( "1234567.89" ).toDouble(&ok); // ok == true |
|