From 8d7227460f1c44d1faa92b853c7ce6bfbb5c37dd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Jan 2023 14:17:34 +0100 Subject: [PATCH] Documentation: Clarify the meaning of the precision parameter for double formatting Move it to the table for QLocale::toString() to make it more prominent. Explain the meaning for QTextStream::realNumberPrecision(). Change-Id: Ic2da22ff6bea09e79e17f19b4636cef35dc3a615 Reviewed-by: Thiago Macieira (cherry picked from commit fe4cc2793f80e285be66c36bc1ec6903ddcd312e) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/serialization/qtextstream.cpp | 7 +++++-- src/corelib/text/qlocale.cpp | 22 +++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index a268002dc68..83e97c834d0 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -1400,7 +1400,8 @@ QTextStream::RealNumberNotation QTextStream::realNumberNotation() const /*! Sets the precision of real numbers to \a precision. This value describes the number of fraction digits QTextStream should - write when generating real numbers. + write when generating real numbers (FixedNotation, ScientificNotation), or + the maximum number of significant digits (SmartNotation). The precision cannot be a negative value. The default value is 6. @@ -1419,7 +1420,9 @@ void QTextStream::setRealNumberPrecision(int precision) /*! Returns the current real number precision, or the number of fraction - digits QTextStream will write when generating real numbers. + digits QTextStream will write when generating real numbers + (FixedNotation, ScientificNotation), or the maximum number of significant + digits (SmartNotation). \sa setRealNumberNotation(), realNumberNotation(), numberFlags(), integerBase() */ diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index fe23dc6450c..0525d5ac23a 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -2613,21 +2613,17 @@ static bool qIsUpper(char c) The \a format defaults to \c{'g'}. It can be any of the following: \table - \header \li Format \li Meaning - \row \li \c 'e' \li format as [-]9.9e[+|-]999 - \row \li \c 'E' \li format as [-]9.9E[+|-]999 - \row \li \c 'f' \li format as [-]9.9 - \row \li \c 'F' \li same as \c 'f' except for INF and NAN (see below) - \row \li \c 'g' \li use \c 'e' or \c 'f' format, whichever is more concise - \row \li \c 'G' \li use \c 'E' or \c 'F' format, whichever is more concise + \header \li Format \li Meaning \li Meaning of \a precision + \row \li \c 'e' \li format as [-]9.9e[+|-]999 \li number of digits \e after the decimal point + \row \li \c 'E' \li format as [-]9.9E[+|-]999 \li " + \row \li \c 'f' \li format as [-]9.9 \li " + \row \li \c 'F' \li same as \c 'f' except for INF and NAN (see below) \li " + \row \li \c 'g' \li use \c 'e' or \c 'f' format, whichever is more concise \li maximum number of significant digits (trailing zeroes are omitted) + \row \li \c 'G' \li use \c 'E' or \c 'F' format, whichever is more concise \li " \endtable - For the \c 'e', \c 'E', \c 'f' and \c 'F' formats, the \a precision - represents the number of digits \e after the decimal point. For the \c 'g' - and \c 'G' formats, the \a precision represents the maximum number of - significant digits (trailing zeroes are omitted). The special \a precision - value QLocale::FloatingPointShortest selects the shortest representation - that, when read as a number, gets back the original floating-point + The special \a precision value QLocale::FloatingPointShortest selects the + shortest representation that, when read as a number, gets back the original floating-point value. Aside from that, any negative \a precision is ignored in favor of the default, 6.