A realistic example where using BigDecimal for currency is strictly better than using double

前端 未结 8 2063
野趣味
野趣味 2020-12-13 06:29

We know that using double for currency is error-prone and not recommended. However, I\'m yet to see a realistic example, where BigDecimal

8条回答
  •  暖寄归人
    2020-12-13 06:55

    When you round double price = 0.615 to two decimal places, you get 0.61 (rounded down) but probably expected 0.62 (rounded up, because of the 5).

    This is because double 0.615 is actually 0.6149999999999999911182158029987476766109466552734375.

提交回复
热议问题