You can use the decimal package . This package allows decimal calculations without loss of precision, such as double operations.
Decimal.parse('0.2') + Decimal.parse('0.1'); // => 0.3
Decimal.parse('0.2')returns a new object Decimalthat can be processed as num(by the way, Decimalit is not num, because it numcannot be used as a superclass or implemented).
To make the code shorter, you can define a shortcut for Decimal.parse:
final d = Decimal.parse;
d('0.2') + d('0.1'); // => 0.3
source
share