This is expected behavior. Double numbers cannot represent all decimal fractions precisely, and neither 0.05
nor 42.05
are the exact values that the double
values represent. The exact values are:
If you add these two exact values, the result can yet again not be represented exactly as a double. The two closest representable doubles are:
Of these, the former is closer to the correct result of the addition, so that is the double
value chosen to represent that result.
This issue is not specific to Dart. All language using IEEE-754 64-bit floating point numbers will get the same result, and that is probably all languages with a 64-bit floating point type (C, C++, C#, Java, JavaScript, etc).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.