parseDouble function

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

Parses v to double.

def The default value if v is invalid.

Implementation

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

  if (v is double) return v;
  if (v is num) return v.toDouble();

  String s;
  if (v is String) {
    s = v;
  } else {
    s = v.toString();
  }

  s = s.trim();

  if (s.isEmpty) return def;

  var n = double.tryParse(s);
  return n ?? def;
}