Castle Wu wrote:
i found a interesting problem here.
i transform a string data "180" to int and then multiple by 0.7
(Integer.parseInt("180"))*0.7
and i got the result of "125.9999999999999999".
why?? @_@"
0.7 doesn't represent too well as a floating point binary value.
While it's a fairly simple value in decimal, in binary it's one of the
infinately repeating numbers (something akin to the square root of 2 in
decimal). Welcome to working with floating point values in the computing
world.
Most systems have code to account for this somewhat, but this tends to
work best when the two values are of the same type. Try your test again
with the 180 represented as a double, and you'll get the correct result.
Brad BARCLAY
--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project:
http://www.jsyncmanager.org