toDouble function
Convert a string or int to double and returns the double value Throws a Error if cant be converted
Implementation
double toDouble(dynamic value) {
double parsedValue;
if (value is String) {
try {
parsedValue = double.parse(value);
} catch (e) {
throw 'the string value "$value" cannot be parsed to a number';
}
} else if (value is int) {
parsedValue = value.toDouble();
} else if (value is double) {
parsedValue = value;
} else {
throw 'type ${value.runtimeType} cannot be parsed to a number type';
}
return parsedValue;
}