close up shot of a casino roulette

Comparing Bigdecimal and Double is tricky because the scale(numbers to the left of .) is higher for BigDecimal as compared to Double.

So you’ll have to decide up to which scale the numbers should be the same to consider both the variables as equal. Once you have decided the limit say 5, you need to multiply both your variables with 10^(your chosen limit) i.e. 10^5 = 100000, and then use a truncation function like Ciel or Floor to ignore the rest of the numbers.

Below is an example code demonstrating the approach:-

Math.ceil(bigDecimalVariable * 100000) == Math.ceil(doubleVariable * 100000);

By spstech

6 thought on “How to compare BigDecimal and Double in Java”
  1. whoah this blog is excellent i like studying your articles. Stay up the good paintings! You recognize, lots of individuals are searching around for this info, you can help them greatly.

  2. Asking questions are really pleasant thing if you are not understanding
    something fully, but this piece of writing presents nice understanding even.

  3. Appreciating the commitment you put into your website and in depth information you provide.
    It’s great to come across a blog every once in a while that isn’t the same old rehashed information. Great read!
    I’ve saved your site and I’m including your RSS feeds to my Google account.

Leave a Reply

Your email address will not be published. Required fields are marked *