getDecimalNumberFormat function

NumberFormat getDecimalNumberFormat({
  1. num? value,
  2. String? locale = 'en_US',
  3. String? pattern = "#,##0.##",
  4. int? minimumFractionDigits,
  5. int? maximumFractionDigits,
})

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 on value.
  • maximumFractionDigits: The maximum number of digits after the decimal to display. If not specified, a default is calculated based on value.

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;
}