toDouble function
Converts an object to a double. mirroring the same static method in the ConvertObject, providing alternative easy less code usage options.
- Converts numeric types and strings that represent valid numbers to double.
- If the conversion to double fails (e.g., non-numeric string), throws a
ParsingException
.
object
The object to be converted to a double.
mapKey
(Optional) Specifies the key to extract values from a Map object.
listIndex
(Optional) Specifies the index to extract elements from a List object.
Returns a double if conversion is successful.
Throws a ParsingException
if the conversion fails.
Example usage:
final object1 = 5.5;
final double1 = toDouble(object1); // 5.5
final object2 = '3.14';
final double2 = toDouble(object2); // 3.14
final object3 = true;
final double3 = toDouble(object3); // 1.0
final object4 = 'abc';
final double4 = toDouble(object4); // throws ParsingException
Implementation
double toDouble(
dynamic object, {
Object? mapKey,
int? listIndex,
String? format,
String? locale,
}) =>
ConvertObject.toDouble(
object,
mapKey: mapKey,
listIndex: listIndex,
format: format,
locale: locale,
);