Number QML Type
숫자 개체는 숫자 값을 나타냅니다. 자세히...
Import Statement: | import QtQml |
메서드
- string fromLocaleString(locale, number)
- string toLocaleCurrencyString(locale, symbol)
- string toLocaleString(locale, format, precision)
상세 설명
QML Number 객체는 로캘 인식 함수를 사용하여 JS Number 객체를 확장합니다.
Locale 를참조하세요 .
메서드 문서
string fromLocaleString(locale, number) |
제공된 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
Locale 를참조하세요 .
string toLocaleCurrencyString(locale, symbol) |
지정된 locale 의 통화 및 규칙을 사용하여 숫자를 통화로 변환합니다. symbol 을 지정하면 통화 기호로 사용됩니다.
Locale::currencySymbol()도 참조하세요 .
string toLocaleString(locale, format, precision) |
지정된 format 에서 지정된 precision 을 사용하여 지정된 locale 에 적합한 문자열로 숫자를 변환합니다.
유효한 형식은 다음과 같습니다:
- '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
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.