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 ?
If you want precision use BigDecimal for arbitrary decimal points.
But the comment of @Aprillion is right: if you do a Java calculation containing doubles then you lose precision, even if the persistence data type is in BigDecimal format.
So use BigDecimal just if you want to ensure proper decimal precision from/to that field.
I hope this helps!