Home · All Classes · All Functions · Overviews

QML NumberFormatter Element Reference

The NumberFormatter allows you to control the format of a number string. More...

Properties

Detailed Description

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 }

Property Documentation

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.

CharacterMeaning
#Any digit(s), zero shows as absent (for leading/trailing zeroes).
0Implicit 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).
otherAny 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.

FormatNumberOutput
###123456123456
000123456123456
######12341234
0000001234001234
##,##0.##1234.4561,234.46 (for US locale)

 1 234,46 (for FR locale)
000000,000.#123456000,123,456 (for US locale)

 000 123 456 (for FR locale)
0.0###0.9999971.0
(000) 000 - 00012345678(012) 345 - 678
#A1212A


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