1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
7 \brief The Number object provides represents a number value.
9 The QML Number object extends the JS Number object with
10 locale aware functions.
12 \sa {QtQml::Locale}{Locale}
16 \qmlmethod string Number::toLocaleString(locale,format,precision)
18 Converts the Number to a string suitable for the specified \a locale
19 in the specified \a format, with the specified \a precision.
23 \li 'f' Decimal floating point, e.g. 248.65
24 \li 'e' Scientific notation using e character, e.g. 2.4865e+2
25 \li 'E' Scientific notation using E character, e.g. 2.4865E+2
26 \li 'g' Use the shorter of e or f
27 \li 'G' Use the shorter of E or f
30 If precision is not specified, the precision will be 2.
32 If the format is not specified 'f' will be used.
34 If \a locale is not specified, the default locale will be used.
36 The following example shows a number formatted for the German locale:
41 text: "The value is: " + Number(4742378.423).toLocaleString(Qt.locale("de_DE"))
45 You can apply toLocaleString() directly to constants, provided the decimal
46 is included in the constant, e.g.
48 123.0.toLocaleString(Qt.locale("de_DE")) // OK
49 123..toLocaleString(Qt.locale("de_DE")) // OK
50 123.toLocaleString(Qt.locale("de_DE")) // fails
55 \qmlmethod string Number::toLocaleCurrencyString(locale,symbol)
57 Converts the Number to a currency using the currency and conventions of the specified
58 \a locale. If \a symbol is specified it will be used as the currency
61 \sa Locale::currencySymbol()
65 \qmlmethod string Number::fromLocaleString(locale,number)
67 Returns a Number by parsing \a number using the conventions of the supplied \a locale.
69 If \a locale is not supplied the default locale will be used.
71 For example, using the German locale:
73 var german = Qt.locale("de_DE");
75 d = Number.fromLocaleString(german, "1234,56") // d == 1234.56
76 d = Number.fromLocaleString(german, "1.234,56") // d == 1234.56
77 d = Number.fromLocaleString(german, "1234.56") // throws exception
78 d = Number.fromLocaleString(german, "1.234") // d == 1234.0