o*********r 发帖数: 203 | 1 I think that it's something to do with the IEEE floating point standard used
in PCs. Not all float/double numbers can be stored precisely. For example,
1/3 can't be stored precisely. Mathematically, 1/3 + 1/3 + 1/3 = 1. But in
computer, it may not be true.
212999 * 1.5 = 319498.5
21299.9 * 10 * 1.5 = 319498.5
2129.99 * 100 * 1.5 = 319498.49999999994
Math.round works as follows:
- for >= 0.5, it rounds up.
- for < 0.5, it rounds down.
So if you add 0.5, the Math.round gives you the right result:... 阅读全帖 |
|