why is java turning integers into something less

This question already has an answer here:

  • Why not use Double or Float to represent currency? 14 answers
  • Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273? 14 answers

  • You're doing your calculations using double.

    Please take a look on this http://floating-point-gui.de/

    Also http://www.mkyong.com/java/how-do-calculate-monetary-values-in-java-double-vs-bigdecimal/


    I admit, I didn't read your code, but I'm 99% sure that you're having a problem with binary datastorage.

    You see, in the decimal system, 1/10 can be easily represented as 0.1. However, try 1/3, it becomes 0.33333333333333333...

    In binary, 1/10 is 0.0001100110011001100110011...

    Look into BigDecimal for base10 numberstorage.

    链接地址: http://www.djcxy.com/p/85816.html

    上一篇: 以Java总计账单

    下一篇: 为什么java将整数转化为更少的东西