parseDouble static method
Parses the dynamic value
into a double. The value
may be a String,
int, or double. If the value
cannot be successfully parsed into a
double then null will be returned.
A value of the string "infinity" will result in double.infinity.
Implementation
static double parseDouble(dynamic value) {
double? result;
try {
if (value is String) {
if (value.toLowerCase() == 'infinity') {
result = double.infinity;
} else if (value.startsWith('0x') == true) {
result = int.tryParse(value.substring(2), radix: 16)?.toDouble();
} else {
result = double.tryParse(value);
}
} else if (value is double) {
result = value;
} else if (value is int) {
result = value.toDouble();
}
} catch (e, stack) {
_logger.finest('Error parsing: $value', e, stack);
}
if (result == null) {
throw Exception(
'Non-nullable parseDouble was called but null was encountered',
);
}
return result;
}