The Number object provides represents a number value. 更多...
import 语句: | import QtQml 2.2 |
The QML Number object extends the JS Number object with locale aware functions.
另请参阅 Locale .
string fromLocaleString ( locale , number ) |
Returns a Number by parsing number using the conventions of the supplied locale .
若 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
string toLocaleCurrencyString ( locale , symbol ) |
Converts the Number to a currency using the currency and conventions of the specified locale 。若 symbol is specified it will be used as the currency symbol.
另请参阅 Locale::currencySymbol() .
string toLocaleString ( locale , format , precision ) |
Converts the Number to a string suitable for the specified locale 以指定 format , with the specified precision .
Valid formats are:
If precision is not specified, the precision will be 2.
If the format is not specified 'f' will be used.
若 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