Doc: harmonize toDouble() and toFloat() for QString and QByteArray
Change-Id: Ic81461899c73c8a68bc3b8bdc1de4be4dd6bdf27 Reviewed-by: Martin Smith <martin.smith@qt.io>
This commit is contained in:
parent
e92e46348a
commit
dc133765ec
@ -353,9 +353,21 @@ long dec = str.toLong(&ok, 10); // dec == 0, ok == false
|
|||||||
|
|
||||||
//! [38]
|
//! [38]
|
||||||
QByteArray string("1234.56");
|
QByteArray string("1234.56");
|
||||||
double a = string.toDouble(); // a == 1234.56
|
bool ok;
|
||||||
|
double a = string.toDouble(&ok); // a == 1234.56, ok == true
|
||||||
|
|
||||||
|
string = "1234.56 Volt";
|
||||||
|
a = str.toDouble(&ok); // a == 0, ok == false
|
||||||
//! [38]
|
//! [38]
|
||||||
|
|
||||||
|
//! [38float]
|
||||||
|
QByteArray string("1234.56");
|
||||||
|
bool ok;
|
||||||
|
double a = string.toFloat(&ok); // a == 1234.56, ok == true
|
||||||
|
|
||||||
|
string = "1234.56 Volt";
|
||||||
|
a = str.toFloat(&ok); // a == 0, ok == false
|
||||||
|
//! [38float]
|
||||||
|
|
||||||
//! [39]
|
//! [39]
|
||||||
QByteArray text("Qt is great!");
|
QByteArray text("Qt is great!");
|
||||||
|
@ -853,6 +853,8 @@ void Widget::toDoubleFunction()
|
|||||||
double d;
|
double d;
|
||||||
|
|
||||||
d = QString( "1234.56e-02" ).toDouble(&ok); // ok == true, d == 12.3456
|
d = QString( "1234.56e-02" ).toDouble(&ok); // ok == true, d == 12.3456
|
||||||
|
|
||||||
|
d = QString( "1234.56e-02 Volt" ).toDouble(&ok); // ok == false, d == 0
|
||||||
//! [67]
|
//! [67]
|
||||||
|
|
||||||
//! [68]
|
//! [68]
|
||||||
@ -875,6 +877,9 @@ void Widget::toFloatFunction()
|
|||||||
bool ok;
|
bool ok;
|
||||||
QString str2 = "R2D2";
|
QString str2 = "R2D2";
|
||||||
str2.toFloat(&ok); // returns 0.0, sets ok to false
|
str2.toFloat(&ok); // returns 0.0, sets ok to false
|
||||||
|
|
||||||
|
QString str3 = "1234.56 Volt";
|
||||||
|
str3.toFloat(&ok); // returns 0.0, sets ok to false
|
||||||
//! [71]
|
//! [71]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4124,9 +4124,16 @@ ushort QByteArray::toUShort(bool *ok, int base) const
|
|||||||
|
|
||||||
\snippet code/src_corelib_tools_qbytearray.cpp 38
|
\snippet code/src_corelib_tools_qbytearray.cpp 38
|
||||||
|
|
||||||
|
\warning The QByteArray 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.
|
||||||
|
|
||||||
\note The conversion of the number is performed in the default C locale,
|
\note The conversion of the number is performed in the default C locale,
|
||||||
irrespective of the user's locale.
|
irrespective of the user's locale.
|
||||||
|
|
||||||
|
This function ignores leading and trailing whitespace.
|
||||||
|
|
||||||
\sa number()
|
\sa number()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -4150,9 +4157,18 @@ double QByteArray::toDouble(bool *ok) const
|
|||||||
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
|
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
|
||||||
to \c false, and success by setting *\a{ok} to \c true.
|
to \c false, and success by setting *\a{ok} to \c true.
|
||||||
|
|
||||||
|
\snippet code/src_corelib_tools_qbytearray.cpp 38float
|
||||||
|
|
||||||
|
\warning The QByteArray 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.
|
||||||
|
|
||||||
\note The conversion of the number is performed in the default C locale,
|
\note The conversion of the number is performed in the default C locale,
|
||||||
irrespective of the user's locale.
|
irrespective of the user's locale.
|
||||||
|
|
||||||
|
This function ignores leading and trailing whitespace.
|
||||||
|
|
||||||
\sa number()
|
\sa number()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user