formatCurrency function

String formatCurrency({
  1. num? value,
  2. String? locale = 'en_US',
  3. String symbol = 'USD',
  4. int? minimumFractionDigits,
  5. int? maximumFractionDigits,
})

Formats a value as a currency string using the given localeand symbol. minimumFractionDigits and maximumFractionDigits can be used to specify the minimum and maximum number of decimal places to display.

Implementation

String formatCurrency({
  num? value,
  String? locale = 'en_US',
  String symbol = 'USD',
  int? minimumFractionDigits,
  int? maximumFractionDigits,
}) {
  if (value == null) return '';

  final formatter = getCurrencyNumberFormat(
    minimumFractionDigits: minimumFractionDigits,
    maximumFractionDigits: maximumFractionDigits,
    symbol: symbol,
    locale: locale,
    value: value,
  );

  return formatter.format(value);
}