nmFormatMoney function

String nmFormatMoney(
  1. BuildContext context,
  2. num amount, {
  3. String currency = 'USD',
})

Amount in currency for the current locale; whole amounts drop the cents ("$186,000", "$2,145.60").

Implementation

String nmFormatMoney(BuildContext context, num amount, {String currency = 'USD'}) {
  final whole = amount == amount.roundToDouble();
  try {
    return NumberFormat.simpleCurrency(locale: _tag(context), name: currency, decimalDigits: whole ? 0 : 2).format(amount);
  } catch (_) {
    return NumberFormat.simpleCurrency(locale: 'en', name: currency, decimalDigits: whole ? 0 : 2).format(amount);
  }
}