getDecimalNumberFormat function
NumberFormat
getDecimalNumberFormat({})
Returns a NumberFormat
for decimal numbers that uses the locale
,
pattern
, 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'.pattern
: The pattern to use for formatting. Defaults to "#,##0.##".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 getDecimalNumberFormat({
num? value,
String? locale = 'en_US',
String? pattern = "#,##0.##",
int? minimumFractionDigits,
int? maximumFractionDigits,
}) {
final (minFractionDigits, maxFractionDigits) = getDefaultFractionDigits(
value ?? 0,
minimumFractionDigits,
maximumFractionDigits,
);
final formatter = NumberFormat(pattern, locale)
..maximumFractionDigits = maxFractionDigits
..minimumFractionDigits = minFractionDigits;
return formatter;
}