toDouble method

double? toDouble()

Converts a numeric string to a double. Returns null if parsing fails or string is empty.

Implementation

double? toDouble() {
  if (this == null) return null;
  final regex = RegExp(r'^-?\d*\.?\d*');
  final match = regex.firstMatch(this!);
  final numericString = match?.group(0);

  if (numericString == null || numericString.isEmpty) return null;
  return double.tryParse(numericString);
}