toCurrency method

String toCurrency({
  1. Currency? currency,
  2. String? code,
  3. bool withPattern = true,
})

Sample: 1234.5.toCurrency(code: 'EUR') => 1 234,50 € Sample (locale 'en_US'): 1234.5.toCurrency(code: 'EUR', withPattern: false) => €1,234.50

Implementation

String toCurrency(
    {Currency? currency, String? code, bool withPattern = true}) {
  fn(Currency? currency, String? locale) => NumberFormat.currency(
        locale: locale,
        symbol: currency?.symbol,
        decimalDigits: currency?.decimalDigits,
        customPattern: generatePattern(
            withPattern ? currency : CurrencyDefaults.defaultCurrency),
      );
  return _convert(fn,
      currency: currency, code: code, withPattern: withPattern);
}