[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()


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(
    algorithm_3 = new BigDecimal(
    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]