dart – How to convert to double

dart – How to convert to double

Remove the quotes from

 var long2 = double.parse($group1);

to

 var long2 = double.parse($group1);

You can also use

var long2 = double.tryParse($group1);

or to also accept numbers without fractions

var long2 = num.tryParse($group1)?.toDouble();

to not get an exception when the string in $group1 can not be converted to a valid double.

Why not use just group1 as in double.parse(group1)

dart – How to convert to double

Leave a Reply

Your email address will not be published. Required fields are marked *