toDouble method
- @Deprecated('This method is deprecated and will be removed in a future release. ' 'Please use other type conversion methods or handle conversions manually.')
Converts the value to a double.
- Returns
0.0
if the value isnull
. - Returns the value if it's already a double.
- Converts and returns the value if it's an int or a String.
- Throws a FormatException if conversion is not possible.
Implementation
@Deprecated(
'This method is deprecated and will be removed in a future release. '
'Please use other type conversion methods or handle conversions manually.',
)
double toDouble() {
if (this == null) {
return 0.0;
} else if (this is double) {
return this as double;
} else if (this is int) {
return (this as int).toDouble();
} else if (this is String) {
return double.tryParse(this as String) ?? 0.0;
} else {
throw FormatException('Cannot convert $this to double');
}
}