Number QML Type

Numberオブジェクトは数値の値を表します。詳細...

Import Statement: import QtQml

メソッド

詳細な説明

QML Number オブジェクトは JS Number オブジェクトをロケール対応関数で拡張したものです。

Localeも参照してください

メソッドの説明

string fromLocaleString(locale, number)

指定されたlocale の規約にしたがってnumber を解析して Number を返します。

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

Localeも参照ください


string toLocaleCurrencyString(locale, symbol)

指定したlocale の通貨および規約を使用して、数値を通貨に変換します。symbol を指定すると、それが通貨記号として使用されます。

Locale::currencySymbol()も参照


string toLocaleString(locale, format, precision)

Converts the Number to a string suitable for the specifiedlocale in the specifiedformat, with the specifiedprecision.

有効な形式は以下のとおり:

  • f' 10 進浮動小数点、例:248.65
  • e' e 文字を使った科学表記法、例:2.4865e+2。
  • 'E' E文字を使った科学表記法、例:2.4865E+2
  • 'g' eまたはfの短い方を使う。
  • 'G' Eまたはfのうち短い方を使う。

精度が指定されていない場合、精度は2となる。

書式が指定されていない場合、'f'が使われる。

locale が指定されなければ、デフォルトのロケールが使われる。

次の例は、ドイツ語ロケール用にフォーマットされた数値を示しています:

import QtQuick 2.0

Text {
    text: "The value is: " +  Number(4742378.423).toLocaleString(Qt.locale("de_DE"))
}

locale の個々のフィールドをカスタマイズして、出力を厳密に制御することができます:

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

toLocaleString()は、定数に直接適用することができます。

123.0.toLocaleString(Qt.locale("de_DE")) // OK
123..toLocaleString(Qt.locale("de_DE"))  // OK
123.toLocaleString(Qt.locale("de_DE"))   // fails

Localeも参照ください


© 2025 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.