Formatting Patterns
Note: the same patterns are used for both formatting and parsing monetary amounts.
The supported pattern characters are:
  • S outputs the currencies symbol e.g. $.
  • C outputs part of the currency code e.g. USD. You can specify 1,2 or 3 C's. Specifying CCC will output the full code regardless of its length.
    • C - U
    • CC - US
    • CCC - USD - outputs the full currency code regardless of length.
  • denotes a digit.
  • 0 denotes a digit and and forces padding with leading and trailing zeros.
  • , (comma) a placeholder for the grouping separtor
  • . (period) a place holder for the decimal separator
Examples:
1
import 'money2.dart';
2
final Currency usd = Currency.create('USD', 2);
3
Money lowPrice = Money.fromInt(1099, usd);
4
print(lowPrice.format('S000.000'));
5
> $010.990
6
​
7
Money costPrice = Money.fromInt(10034530, usd); // 100,345.30 usd
8
​
9
print(costPrice.format('###,###.##'));
10
> 100,345.30
11
​
12
print(costPrice.format('S###,###.##'));
13
> $100,345.3
14
​
15
print(costPrice.format('CC###,###.#0'));
16
> US100,345.30
17
​
18
print(costPrice.format('CCC###,###.##'));
19
> USD100,345.3
20
​
21
print(costPrice.format('SCC###,###.#0'));
22
> $US100,345.30
23
​
24
final usd = Currency.create('USD', 2);
25
Money costPrice = Money.fromInt(10034530, usd); // 100,345.30 usd
26
print(costPrice.format('SCC###,###.##'));
27
> $US100,345.3
28
​
29
final jpy = Currency.create('JPY', 0, symbol: 'Β₯');
30
Money costPrice = Money.fromInt(345, jpy); // 345 yen
31
print(costPrice.format('SCCC#'));
32
> Β₯JPY345
33
​
34
// Bahraini dinar
35
final bhd = Currency.create('BHD', 3, symbol: 'BD', invertSeparators: true);
36
Money costPrice = Money.withInt(100345, bhd); // 100.345 bhd
37
print(costPrice.format('SCCC0000,###'));
38
> BDBHD0100,345
Copied!
Copy link