parseDoubleIntoAmount method
Formats the double into a human-readable amount with decimals decimals,
using a comma (,) as decimal separator and spaces ( ) as thousands separators.
Example:
12345.678.parseDoubleIntoAmount(); // "12 345,68"
12345.6.parseDoubleIntoAmount(decimals: 0); // "12 346"
Implementation
String parseDoubleIntoAmount({ int decimals = 2 }) {
String parsed = toStringAsFixed(decimals).replaceAll('.', ',');
final result = parsed.replaceAllMapped(
RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]} ');
return result;
}