Formatting

Fixed allows you to format numbers to strings.

The following format characters are supported:

# - print a digit if present
0 - print a digit if present else 0. Used to pad strings with zeros.
. - print a dot. The invertSeparator parameter controls if this is treated 
       as a decimal place or a group separator.
, - print a comma. The invertSeparator parameter controls if this is treated 
       as a decimal place or a group separator.       

Internationally the '.' and ',' characters are used differently.

USA, UK, Australia etc

In countries such as the USA, UK and Australia the '.' (dot) is used as the delimiter between integer and decimal parts of a number whilst the ',' (comma) is used to group thousands.

Eleven Hundred dollars and 22 cents.

$1,100.22

In Europe and other countries the '.' (dot) and ',' (comma) are reversed:

Europian countries etc

Eleven Hundred dollars and 22 cents.

$1.100,22

Inverting separators

When formating a number you use the 'invertSeparator' argument to control who the separators character are used. By default, the USA, UK and Australia method is used. Pass invertSperator: false to use the European variation.

Example 4

var t3 = Fixed.fromInt(1234, scale: 3); // == 1.234

t3.format('00.###0'); // == '01.2340'

// format using euro separators
t3.format('00,###0', invertSeparator: true);  // == '01,2340'

var euFormat = Fixed.parse('1.000.000,23', invertSeparator: true, scale: 2);
// Format using a locale
euFormat.formatIntl('en-AUS'); // == '1,000,000.23'

// Format using default locale
euFormat.formatIntl(); // '1,000,000.23'

Last updated