toDoubleSafe method

double? toDoubleSafe()

Converts this string to a double, removing commas and other formatting first.

Returns null if the string cannot be parsed as a number.

Example:

String text = '11,111.50';
double? value = text.toDoubleSafe(); // 11111.50

Implementation

double? toDoubleSafe() {
  final cleaned = numbersWithDecimal;
  if (cleaned.isEmpty) return null;
  return double.tryParse(cleaned);
}