![]() |
Home · All Classes · All Functions · Overviews |
The NumberFormatter allows you to control the format of a number string. More...
The format property documentation has more details on how the format can be manipulated.
In the following example, the text element will display the text "1,234.57".
NumberFormatter { id: formatter; number: 1234.5678; format: "##,##0.##" } Text { text: formatter.text }
format : string |
The particular format the number will adhere to during the conversion to text.
The format syntax follows a style similar to the Unicode Standard (UTS35).
The table below shows the characters, patterns that can be used in the format.
Character | Meaning |
---|---|
# | Any digit(s), zero shows as absent (for leading/trailing zeroes). |
0 | Implicit digit. Zero will show in the case that the input number is too small. |
. | Decimal separator. Output decimal seperator will be dependant on system locale. |
, | Grouping separator. The number of digits (either #, or 0) between the grouping separator and the decimal (or the rightmost digit) will determine the groupingSize). |
other | Any other character will be taken as a string literal and placed directly into the output string. |
Invalid formats will not guarantee a meaningful text output.
Note: Input numbers that are too long for the given format will be rounded dependent on precison based on the position of the decimal point.
The following table illustrates the output text created by applying some examples of numeric formats to the formatter.
Format | Number | Output |
---|---|---|
### | 123456 | 123456 |
000 | 123456 | 123456 |
###### | 1234 | 1234 |
000000 | 1234 | 001234 |
##,##0.## | 1234.456 | 1,234.46 (for US locale) 1 234,46 (for FR locale) |
000000,000.# | 123456 | 000,123,456 (for US locale) 000 123 456 (for FR locale) |
0.0### | 0.999997 | 1.0 |
(000) 000 - 000 | 12345678 | (012) 345 - 678 |
#A | 12 | 12A |
number : real |
A single point precision number. (Doubles are not yet supported)
text : string |
The number in the specified format.
If no format is specified the text will be empty.
Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.7.0 |