How to convert BigDecimal to Double in Java?

Java

Java Problem Overview


How we convert BigDecimal into Double in java? I have a requirement where we have to use Double as argument but we are getting BigDecimal so i have to convert BigDecimal into Double.

Java Solutions


Solution 1 - Java

You need to use the doubleValue() method to get the double value from a BigDecimal object.

BigDecimal bd; // the value you get
double d = bd.doubleValue(); // The double you want

Solution 2 - Java

You can convert BigDecimal to double using .doubleValue(). But believe me, don't use it if you have currency manipulations. It should always be performed on BigDecimal objects directly. Precision loss in these calculations are big time problems in currency related calculations.

Solution 3 - Java

Use doubleValue method present in BigDecimal class :

double doubleValue()

Converts this BigDecimal to a double.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSubodh JoshiView Question on Stackoverflow
Solution 1 - JavaRahulView Answer on Stackoverflow
Solution 2 - JavaHIREN011View Answer on Stackoverflow
Solution 3 - JavaJuned AhsanView Answer on Stackoverflow