0

I have database with oracle number type. Could there any possible issues with using java Double when updating table with numeric column. Should i switch BigDecimal or Double is approriate type.

As I fas as I know, BigDecimal is used when arbitrary precision required, when deal with prices for example.

Consider simple API updatePrice(Double d) Should i persist double as is or BigDecimal.valueOf(d) is preferable ?

4

1 回答 1

2

如果您想要精确使用 BigDecimal 任意小数点。

但是@Aprillion 的评论是正确的:如果您执行包含双精度的 Java 计算,那么即使持久性数据类型是 BigDecimal 格式,您也会失去精度。

因此,如果您想确保从/到该字段的正确小数精度,请使用 BigDecimal。

我希望这有帮助!

于 2012-07-02T13:15:30.753 回答