parseDouble static method

double? parseDouble(
  1. Object? value, [
  2. double? def
])

Tries to parse a double.

  • Returns def if value is invalid.

Implementation

static double? parseDouble(Object? value, [double? def]) {
  if (value == null) return def;

  if (value is double) {
    return value;
  } else if (value is num) {
    return value.toDouble();
  } else if (value is DateTime) {
    return value.millisecondsSinceEpoch.toDouble();
  } else {
    var n = _parseNumString(value);
    return n?.toDouble() ?? def;
  }
}