What to do with Java BigDecimal performance?

后端 未结 20 2497
陌清茗
陌清茗 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:26

    Can you provide more insight as to the purpose of the calculation?

    What your dealing with is a trade-off between speed and precision. How great will the loss in precision be if you switched to a primitive?

    I think in some cases the user may be comfortable with less accuracy in exchange for speed, so long as they can hone in on the accurate calculation when needed. It really depends on what you will use this calculation for.

    Perhaps you can allow the user to preview the result quickly using doubles, and then request the more precise value using BigDecimal if they wish?

提交回复
热议问题