자바스크립트 Number 객체
QML Number 객체는 로케일을 인식하는 함수를 통해 JS Number 객체를 확장합니다.
string Number::toLocaleString(locale, format, precision)
Number를 지정된 format 에서 지정된 locale 에 적합하고, 지정된 precision 을 가진 문자열로 변환합니다.
유효한 형식은 다음과 같습니다.
- 'f' 십진 부동 소수점, 예: 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")) // failsstring Number::toLocaleCurrencyString(locale, symbol)
지정된 locale 의 통화 및 규칙을 사용하여 Number를 통화로 변환합니다. ` symbol `가 지정된 경우, 이를 통화 기호로 사용합니다.
string Number::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.0Locale 및 Locale::currencySymbol()도 참조하십시오 .
© 2026 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.