Number QML Type
The Number object provides represents a number value More...
Import Statement: | import QtQml 2.2 |
Methods
- string fromLocaleString(locale, number)
- string toLocaleCurrencyString(locale, symbol)
- string toLocaleString(locale, format, precision)
Detailed Description
The QML Number object extends the JS Number object with locale aware functions.
See also Locale.
Method Documentation
Returns a Number by parsing number using the conventions of the supplied locale.
If locale is not supplied the default locale will be used.
For example, using the German locale:
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
Converts the Number to a currency using the currency and conventions of the specified locale. If symbol is specified it will be used as the currency symbol.
See also Locale::currencySymbol().
Converts the Number to a string suitable for the specified locale in the specified format, with the specified precision.
Valid formats are:
- 'f' Decimal floating point, e.g. 248.65
- 'e' Scientific notation using e character, e.g. 2.4865e+2
- 'E' Scientific notation using E character, e.g. 2.4865E+2
- 'g' Use the shorter of e or f
- 'G' Use the shorter of E or f
If precision is not specified, the precision will be 2.
If the format is not specified 'f' will be used.
If locale is not specified, the default locale will be used.
The following example shows a number formatted for the German locale:
import QtQuick 2.0 Text { text: "The value is: " + Number(4742378.423).toLocaleString(Qt.locale("de_DE")) }
You can apply toLocaleString() directly to constants, provided the decimal is included in the constant, e.g.
123.0.toLocaleString(Qt.locale("de_DE")) // OK 123..toLocaleString(Qt.locale("de_DE")) // OK 123.toLocaleString(Qt.locale("de_DE")) // fails
© 2015 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.