Java BigDecimal to Double

Java BigDecimal to Double

In this post, we will see how to convert BigDecimal to Double in java.

Convert BigDecimal to Double in Java

You can simple use BigDecimal’s doubleValue() to convert BigDecimal to Double in java.

Output:

Double value: 22.2345

BigDecimal to double with 2 decimal places

If you want to restrict double to 2 decimal places, you can use BigDecimal’s setScale() method. You can use RoundMode to specify rounding behavior.

Output:

Double upto 2 decimal places: 2.33
Double upto 2 decimal places – RoundingMode.DOWN: 2.32
Double upto 2 decimal places – RoundingMode.UP: 2.33

That’s all about Java BigDecimal to Double.

Was this post helpful?

Leave a Reply

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