diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-10-13 13:44:23 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-10-18 06:37:14 +0000 |
commit | f2eab492ca027437b66d0d315284ea07c3571b24 (patch) | |
tree | 62ba6d7ddbddca5417e4213a4ca5778f022cb53c | |
parent | 77b15b954c31dfa3452bdabf9262cb8bae2bdef2 (diff) |
QtQml: Improve documentation of Number object
Mention that you can customize the locale to gain more control over the
output.
Fixes: QTBUG-91198
Change-Id: I8dec742fcd7d6675de3580538b86f47e5037f25b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 1c076189ce29552bda15ab36c896d99679c5eb75)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 443a0606f2e73a2e63034dc621e09943e86f0661)
-rw-r--r-- | src/qml/doc/src/javascript/number.qdoc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/qml/doc/src/javascript/number.qdoc b/src/qml/doc/src/javascript/number.qdoc index 7676a7cd4f..a37fd8051b 100644 --- a/src/qml/doc/src/javascript/number.qdoc +++ b/src/qml/doc/src/javascript/number.qdoc @@ -34,21 +34,32 @@ If \a locale is not specified, the default locale will be used. The following example shows a number formatted for the German locale: - \code + \qml import QtQuick 2.0 Text { text: "The value is: " + Number(4742378.423).toLocaleString(Qt.locale("de_DE")) } - \endcode + \endqml + + You can customize individual fields of the \a{locale} to tightly control + the output: + \qml + let locale = Qt.locale("de_DE"); + let a = Number(1000).toLocaleString(locale)); // a == 1.000,00 + locale.numberOptions = Locale.OmitGroupSeparator; + let b = Number(1000).toLocaleString(locale)); // b == 1000,00 + \endqml You can apply toLocaleString() directly to constants, provided the decimal is included in the constant, e.g. - \code + \qml 123.0.toLocaleString(Qt.locale("de_DE")) // OK 123..toLocaleString(Qt.locale("de_DE")) // OK 123.toLocaleString(Qt.locale("de_DE")) // fails - \endcode + \endqml + + \sa {QtQml::Locale}{Locale} */ /*! @@ -69,12 +80,14 @@ If \a locale is not supplied the default locale will be used. For example, using the German locale: - \code + \qml var german = Qt.locale("de_DE"); var d; d = Number.fromLocaleString(german, "1234,56") // d == 1234.56 d = Number.fromLocaleString(german, "1.234,56") // d == 1234.56 d = Number.fromLocaleString(german, "1234.56") // throws exception d = Number.fromLocaleString(german, "1.234") // d == 1234.0 - \endcode + \endqml + + \sa {QtQml::Locale}{Locale} */ |