Java.math.BigDecimal.doubleValue() Method

Advertisements


Description

The java.math.BigDecimal.doubleValue() converts this BigDecimal to a double. If this BigDecimal has too great a magnitude represent as a double, it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate. Even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value.

Declaration

Following is the declaration for java.math.BigDecimal.doubleValue() method

public double doubleValue()

Specified by

  • doubleValue in class Number

Parameters

  • NA

Return Value

This method returns this BigDecimal converted to a double.

Exception

  • NA

Example

The following example shows the usage of math.BigDecimal.doubleValue() method

package com.tutorialspoint;

import java.math.*;

public class BigDecimalDemo {

   public static void main(String[] args) {

      // create a BigDecimal object
      BigDecimal bg;

      // create a Double object
      Double d;

      bg=new BigDecimal("1234");

      // assign the converted value of bg to d
      d=bg.doubleValue();

      String str = "Double value of " + bg + " is " + d;

      // print d value
      System.out.println( str );
   }
}

Let us compile and run the above program, this will produce the following result:

Double value of 1234 is 1234.0



Advertisements
Advertisements