이 페이지에서

숫자 자바스크립트 객체

QML 숫자 객체는 로캘 인식 함수를 사용하여 JS 숫자 객체를 확장합니다.

문자열 Number::toLocaleString(로캘, 형식, 정밀도)

locale Number를 지정된 format 에서 지정된 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

상수에 10진수가 포함되어 있는 경우 상수에 직접 toLocaleString()을 적용할 수 있습니다(예

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

문자열 Number::toLocaleCurrencyString(로캘, 심볼)

지정된 locale 의 통화 및 규칙을 사용하여 숫자를 통화로 변환합니다. symbol 이 지정되면 통화 기호로 사용됩니다.

문자열 Number::fromLocaleString(로캘, 숫자)

제공된 locale 의 규칙을 사용하여 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

LocaleLocale::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.