formatCurrency method

String formatCurrency({
  1. String symbol = '\$',
  2. int decimals = 2,
})

Formats the number as currency.

Example:

1234.formatCurrency(); // '\$1,234.00'
1234.formatCurrency(symbol: '€'); // '€1,234.00'

Implementation

String formatCurrency({String symbol = '\$', int decimals = 2}) {
  return '$symbol${formatWithSeparator()}.${decimals.toString().padLeft(decimals, '0')}';
}