1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the documentation of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:FDL$
10 ** GNU Free Documentation License
11 ** Alternatively, this file may be used under the terms of the GNU Free
12 ** Documentation License version 1.3 as published by the Free Software
13 ** Foundation and appearing in the file included in the packaging of
17 ** Alternatively, this file may be used in accordance with the terms
18 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
30 \inqmlmodule QtQuick 2
31 \brief The Number object provides represents a number value
33 The QML Number object extends the JS Number object with
34 locale aware functions.
36 \sa {QtQuick2::Locale}{Locale}
40 \qmlmethod string Number::toLocaleString(locale,format,precision)
42 Converts the Number to a string suitable for the specified \a locale
43 in the specified \a format, with the specified \a precision.
47 \o 'f' Decimal floating point, e.g. 248.65
48 \o 'e' Scientific notation using e character, e.g. 2.4865e+2
49 \o 'E' Scientific notation using E character, e.g. 2.4865E+2
50 \o 'g' Use the shorter of e or f
51 \o 'G' Use the shorter of E or f
54 If precision is not specified, the precision will be 2.
56 If the format is not specified 'f' will be used.
58 If \a locale is not specified, the default locale will be used.
60 The following example shows a number formatted for the German locale:
65 text: "The value is: " + Number(4742378.423).toLocaleString(Qt.locale("de_DE"))
69 You can apply toLocaleString() directly to constants, provided the decimal
70 is included in the constant, e.g.
72 123.0.toLocaleString(Qt.locale("de_DE")) // OK
73 123..toLocaleString(Qt.locale("de_DE")) // OK
74 123.toLocaleString(Qt.locale("de_DE")) // fails
79 \qmlmethod string Number::toLocaleCurrencyString(locale,symbol)
81 Converts the Number to a currency using the currency and conventions of the specified
82 \a locale. If \a symbol is specified it will be used as the currency
85 \sa Locale::currencySymbol()
89 \qmlmethod string Number::fromLocaleString(locale,number)
91 Returns a Number by parsing \a number using the conventions of the supplied \a locale.
93 If \a locale is not supplied the default locale will be used.
95 For example, using the German locale:
97 var german = Qt.locale("de_DE");
99 d = Number.fromLocaleString(german, "1234,56) // d == 1234.56
100 d = Number.fromLocaleString(german, "1.234,56") // d == 1234.56
101 d = Number.fromLocaleString(german, "1234.56") // throws exception
102 d = Number.fromLocaleString(german, "1.234") // d == 1234.0