From f731ed9bcf7c359a3387b5bb2fb491c8ef96fae3 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 16 Jun 2018 20:58:01 +0200 Subject: [PATCH] QString: Harmonize the toFloat() and toDouble() documentation Both use QLocale::toDouble behind the scenes, so the same limitations apply. Document them for toFloat() also. Change-Id: I954362a0db203630685c034df6a921fa6447a509 Reviewed-by: Martin Smith --- src/corelib/tools/qstring.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 3787c496b2..a737d70a9c 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -7207,21 +7207,30 @@ double QString::toDouble(bool *ok) const /*! Returns the string converted to a \c float value. - If a conversion error occurs, *\a{ok} is set to \c false; otherwise - *\a{ok} is set to \c true. Returns 0.0 if the conversion fails. + Returns 0.0 if the conversion fails. - This function ignores leading and trailing whitespace. + If a conversion error occurs, *\a{ok} is set to \c false; otherwise + *\a{ok} is set to \c true. + + \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. The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toFloat() + For historical reasons, this function does not handle + thousands group separators. If you need to convert such numbers, + use QLocale::toFloat(). + Example: \snippet qstring/main.cpp 71 This function ignores leading and trailing whitespace. - \sa number(), toDouble(), toInt(), QLocale::toFloat() + \sa number(), toDouble(), toInt(), QLocale::toFloat(), trimmed() */ float QString::toFloat(bool *ok) const