[an error occurred while processing this directive]

Java BigDecimal doubleValue example

                         

Java bigdecimal class doubleValue() method translates bigdecimal value in to double type value. Method throws NumberFormatException if it finds a String bigdecimal value instead of a integer or double value. In the example four bigdecimal objects namely: algorithm_0, algorithm_1, algorithm_2 & algorithm_3 respectively have been created. Except the first object rest all objects are assigned positive decimal values with  java.lang.Math class fields and methods. 

In the example along with method generated result, original BigDecimal value is also shown 

Syntax for using the method: public double doubleValue()
System.out.println(bigdecimal_objectName.doubleValue()));

Java_BigDecimal_doubleValue.java

import java.math.BigDecimal;


public class Java_BigDecimal_doubleValue {
  public static void main(String args[]) {
    
    BigDecimal algorithm_0 = new BigDecimal(-2.523),
    algorithm_1 = new BigDecimal(Math.E),
    algorithm_2 = new BigDecimal(
      Math.cos(Math.toRadians(60.0))),
    algorithm_3 = new BigDecimal(
      Math.toDegrees(Math.tan(Math.toRadians(60.0))));  
    
    
    BigDecimal operation[] 
    {algorithm_0, algorithm_1, algorithm_2, algorithm_3};
    System.out.println("BigDecimal objects values " +
        "\n'algorithm_0 '\nvalue : " + operation[0]
        +"\ndouble value : " + operation[0].doubleValue());
  
    System.out.println("\n'algorithm_1 '\nvalue : " + operation[1]
            +"\ndouble value : " + operation[1].doubleValue());

    System.out.println("\n'algorithm_2 '\nvalue : " + operation[2]
            +"\ndouble value : " + operation[2].doubleValue());

    System.out.println("\n'algorithm_3 '\nvalue : " + operation[3]
            +"\ndouble value : " + operation[3].doubleValue());
  }
}

Download the code

                         

[an error occurred while processing this directive]