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 ?

1
  • 4
    there is no point in converting imprecise Double numbers to precise but wrong BigDecimals... Commented Jul 1, 2012 at 21:14

1 Answer 1

2

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.