diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-11-09 11:48:39 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-11-24 14:01:08 +0000 |
commit | 4c2dd1a9c1559b4f925a907a832580867dda91e5 (patch) | |
tree | 86904086b27df70f584443e03a3611d9ee24a1b7 /src/corelib/tools/qlocale_tools.cpp | |
parent | 5c8c4d0b2127a5110e05fa4afa1b8883cc91a5df (diff) |
Centralize dropping of trailing zeroes when converting doubles
We're never interested in trailing zeroes, unless the number is exactly
0. qdtoa would return an empty string if the result was exactly '0',
which is also fixed by this change.
Change-Id: I3ba2f7e835b92d54d9008ad03fdf6ce5fb3af8a4
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/corelib/tools/qlocale_tools.cpp')
-rw-r--r-- | src/corelib/tools/qlocale_tools.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/tools/qlocale_tools.cpp index cdc654904e..f766a301c5 100644 --- a/src/corelib/tools/qlocale_tools.cpp +++ b/src/corelib/tools/qlocale_tools.cpp @@ -267,6 +267,8 @@ void doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, char * } } #endif // QT_NO_DOUBLECONVERSION || QT_BOOTSTRAPPED + while (length > 1 && buf[length - 1] == '0') // drop trailing zeroes + --length; } double asciiToDouble(const char *num, int numLen, bool &ok, int &processed) @@ -546,10 +548,6 @@ QString qdtoa(qreal d, int *decpt, int *sign) doubleToAscii(d, QLocaleData::DFSignificantDigits, QLocale::FloatingPointShortest, result, QLocaleData::DoubleMaxSignificant + 1, nonNullSign, length, nonNullDecpt); - // Skip trailing zeroes. The DoubleMaxSignificant precision is the worst case. - while (length > 0 && result[length - 1] == '0') - --length; - if (sign) *sign = nonNullSign ? 1 : 0; if (decpt) |