formatNumberWithComma method

String formatNumberWithComma({
  1. String separator = ',',
})

Formats a number in the string with a comma separator (e.g., 1000 -> 1,000).

Implementation

String formatNumberWithComma({String separator = ','}) {
  return validate().replaceAllMapped(
    RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'),
    (Match m) => '${m[1]}$separator',
  );
}