What to do with Java BigDecimal performance?

后端 未结 20 2496
陌清茗
陌清茗 2020-11-29 17:28

I write currency trading applications for living, so I have to work with monetary values (it\'s a shame that Java still doesn\'t have decimal float type and has nothing to s

20条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 18:08

    Personally, I don't think BigDecimal is ideal for this.

    You really want to implement your own Money class using longs internally to represent the smallest unit (i.e. cent, 10th cent). There is some work in that, implementing add() and divide() etc, but it's not really that hard.

提交回复
热议问题