Why does double.parse ("1833.35")
return value 1833.349999999999
?
It's because floating-point values are represented in the machine with binary exponents, and 10 is not an even power of 2. Thus, some base-10 fractions turn into repeating fractions when converted.
To illustrate, just work out how you'd represent 35/100 in binary.
You could switch to using a decimal instead of a double if you need it to be absolutely correct. Decimal stores the number with a base 10 exponent.
There is no way to represent.35 exactly using a double or float.
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.