currency static method

String currency(
  1. num value, {
  2. String symbol = '\$',
  3. int decimals = 2,
})

Formats a number as currency

Example:

NumberFormatters.currency(1234.56); // '\$1,234.56'

Implementation

static String currency(num value, {String symbol = '\$', int decimals = 2}) {
  final formatted = value.toStringAsFixed(decimals);
  final parts = formatted.split('.');
  final integerPart = withSeparator(int.parse(parts[0]));
  return '$symbol$integerPart.${parts[1]}';
}