toCurrency method
String
toCurrency({
- CurrencyCountry country = CurrencyCountry.ID,
- bool usingSymbol = true,
- int decimalDigits = 0,
Converts the numeric string into formatted currency using CurrencyCountry.
Example:
"15000".toCurrency(country: CurrencyCountry.US); // "$15,000"
Implementation
String toCurrency({
CurrencyCountry country = CurrencyCountry.ID,
bool usingSymbol = true,
int decimalDigits = 0,
}) {
final value = toDouble() ?? 0.0;
final formatter = NumberFormat.currency(
locale: country.locale,
symbol: usingSymbol ? country.symbol : '',
decimalDigits: decimalDigits,
);
return formatter.format(value).trim();
}