tryParseDouble function

double? tryParseDouble(
  1. dynamic value
)

Attempts to parse a dynamic value to a double.

This function tries to convert the provided value to a double. If the value cannot be parsed or is invalid, it returns null.

  • Parameters:

    • value: A dynamic value that is expected to be convertible to a double.
  • Returns: A double if the parsing is successful, or null if parsing fails.

  • Example:

tryParseDouble('3.14');    // returns 3.14
tryParseDouble('abc');     // returns null
tryParseDouble(10);        // returns 10.0 (automatic conversion from int)
tryParseDouble(null);      // throws error (null cannot be converted to String)

Implementation

double? tryParseDouble(dynamic value) {
  return double.tryParse(value.toString());
}