BigDecimal Error

后端 未结 5 1811
走了就别回头了
走了就别回头了 2021-01-13 01:58

In Java, I have defined k as double k=0.0;

I am taking data from database and adding the same using while loop,

while(rst.         


        
5条回答
  •  春和景丽
    2021-01-13 02:16

    As to your second question, double is a binary floating point number. This means that it is expressed as a sum of powers of two. Don't ever use those for calculating monetary values. (if that's what you're summing up there). BigDecimal uses decimal arithmetic, so this is more in line to what we use.

    Numbers such as 0.1 are infinite fractions in binary, in this case: 0.000110011... thus you cannot get a reliable and exact result from using double.

提交回复
热议问题