numbersWithDecimal property
String
get
numbersWithDecimal
Removes all characters except digits and decimal point (0-9 and .).
This is useful for parsing numeric input that may contain commas or other formatting.
Example:
String text = '11,111.50';
String cleaned = text.numbersWithDecimal; // '11111.50'
String price = '\$1,234.56';
String numeric = price.numbersWithDecimal; // '1234.56'
Implementation
String get numbersWithDecimal {
// Remove everything except digits and decimal point
String cleaned = replaceAll(RegExp(r'[^0-9.]'), '');
// Ensure only one decimal point
final parts = cleaned.split('.');
if (parts.length > 2) {
// If multiple decimal points, keep only the first one
cleaned = '${parts[0]}.${parts.sublist(1).join()}';
}
return cleaned;
}