addThousandsSeparator method
String Formatting: Extensions for formatting strings, such as adding thousands separators to a number string.
Implementation
String addThousandsSeparator() {
final parts = split('.');
final wholePart = parts[0].replaceAllMapped(
RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'),
(match) => '${match.group(1)},',
);
if (parts.length > 1) {
return '$wholePart.${parts[1]}';
}
return wholePart;
}