intlToDoubleFormatted method
Attempts to parse the string to a double and format it with two decimal places using intl NumberFormat
Example:
String formattedNumber = "1234.5678".intlToDoubleFormatted();
// Result: "1,234.57"
String originalText = "hello".intlToDoubleFormatted();
// Result: "hello"
Implementation
String intlToDoubleFormatted() {
try {
final number = double.parse(this);
final formatter = NumberFormat('#,##0.00');
return formatter.format(number);
} catch (e) {
return this;
}
}