Why is BigDecimal returning a weird value?

前端 未结 6 595
花落未央
花落未央 2021-01-04 02:59

I am writing code that will deal with currencies, charges, etc. I am going to use the BigDecimal class for math and storage, but we ran into something weird with it.

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 03:58

    If you don't need fractional cents, consider storing and manipulating the currency as an integer, then dividing by 100 when it's time to display. I find that easier than dealing with the inevitable precision issues of storing and manipulating in floating point.

提交回复
热议问题