formatPercentage function

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

Formats a value as a percentage 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 formatPercentage({
  num? value,
  String? locale = 'en_US',
  String? pattern = "#,##0.##",
  int? minimumFractionDigits,
  int? maximumFractionDigits,
}) {
  if (value == null) return '';

  final number = formatDecimal(
    minimumFractionDigits: minimumFractionDigits,
    maximumFractionDigits: maximumFractionDigits,
    value: value * 100,
    pattern: pattern,
    locale: locale,
  );

  return '$number%';
}