getCurrencyNumberFormat function
NumberFormat
getCurrencyNumberFormat({})
Returns a NumberFormat
for currency that uses the locale
,
symbol
, and specific fraction digits defined by the user.
value
: The number to format, used to determine default fraction digits if they are not specified.locale
: The locale to use for formatting. Defaults to 'en_US'.symbol
: The currency symbol to use in formatting. Defaults to 'USD', and is converted to uppercase.minimumFractionDigits
: The minimum number of digits after the decimal to display. If not specified, a default is calculated based onvalue
.maximumFractionDigits
: The maximum number of digits after the decimal to display. If not specified, a default is calculated based onvalue
.
Implementation
NumberFormat getCurrencyNumberFormat({
num? value,
String? locale = 'en_US',
String symbol = 'USD',
int? minimumFractionDigits,
int? maximumFractionDigits,
}) {
final (minFractionDigits, maxFractionDigits) = getDefaultFractionDigits(
value ?? 0,
minimumFractionDigits,
maximumFractionDigits,
);
symbol = symbol.toUpperCase();
final formatter = NumberFormat.simpleCurrency(locale: locale, name: symbol)
..maximumFractionDigits = maxFractionDigits
..minimumFractionDigits = minFractionDigits;
return formatter;
}