formatDecimal function

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

Formats a value as a decimal string using the given locale and pattern. minimumFractionDigits and maximumFractionDigits can be used to specify the minimum and maximum number of decimal places to display.

Implementation

String formatDecimal({
  num? value,
  String? locale = 'en_US',
  String? pattern = "#,##0.##",
  int? minimumFractionDigits,
  int? maximumFractionDigits,
}) {
  if (value == null) return '';

  final formatter = getDecimalNumberFormat(
    minimumFractionDigits: minimumFractionDigits,
    maximumFractionDigits: maximumFractionDigits,
    pattern: pattern,
    locale: locale,
    value: value,
  );

  return formatter.format(value);
}