doubleFromJson static method
Implementation
static double? doubleFromJson(Map<String, dynamic> json, String attribute,
{int decimal = 2, double? defaultValue}) {
try {
if (json[attribute] != null) {
if (json[attribute] is double) {
return double.parse(json[attribute].toStringAsFixed(decimal));
}
if (json[attribute] is int) {
return double.parse(
json[attribute].toDouble().toStringAsFixed(decimal));
}
return double.parse(
double.tryParse(json[attribute])!.toStringAsFixed(decimal));
}
return defaultValue;
} catch (e) {
throw Exception('Error while parsing $attribute[$e]');
}
}