format method
Provides a simple means of formating a Money instance as a string.
pattern
supports the following characters
- S outputs the currencies symbol e.g. $.
- C outputs part of the currency symbol e.g. USD.
You can specify 1,2 or 3 C's
- C - U
- CC - US
- CCC - USD - outputs the full currency isoCode regardless of length.
- # denotes a digit.
- 0 denotes a digit and with the addition of defining leading and trailing zeros.
- , (comma) a placeholder for the grouping separtor
- . (period) a place holder fo rthe decimal separator
Note: even if you use the groupSeparator or decimalSeparator to use alternate separators the pattern must still use ',' and '.' for the group and decimal separators respectively. This method allows a single pattern to be used by multiple currencies.
Example:
Currency aud = Currency.create('AUD', 2, pattern:r'$0.00');
Money costPrice = Money.fromInt(1000, aud);
costPrice.toString();
> $10.00
Money taxInclusive = costPrice * 1.1;
taxInclusive.toString();
> $11.00
taxInclusive.format('SCCC0.00');
> $AUD11.00
taxInclusive.format('SCCC0');
> $AUD11
Implementation
String format(String pattern) => encodedBy(PatternEncoder(this, pattern));