From 4c2dd1a9c1559b4f925a907a832580867dda91e5 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 9 Nov 2015 11:48:39 +0100 Subject: 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 --- src/corelib/tools/qlocale_tools.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools/qlocale_tools.cpp') 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) -- cgit v1.2.3