parseIntIntoAmount method

String parseIntIntoAmount()

Formats the int into a human-readable amount with spaces as thousands separators.

Example:

1234567.parseIntIntoAmount(); // "1 234 567"
(-1234).parseIntIntoAmount(); // "-1 234"

Implementation

String parseIntIntoAmount() {
  final result = toString().replaceAllMapped(
      RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]} ');
  return result;
}