Convert Object to Double

Ads
 

Convert Object to Double

In this section, we are going to convert an object type data into a double.

In this section, we are going to convert an object type data into a double.

Convert Object to Double

     

In this section, we are going to convert an object type data into a double. 

Code Description:

The given program helps you in converting an object type data into a double. An object contains a data 10. Firstly, we convert into a string format then we pass into the valueOf() method. And we follow similar process to double conversion. Finally, we get the converted value into a double. 

valueOf(): This method returns a double object value and the double value represented by the parameter string (str).

Here is the code of this program:

import java.io.*;
import java.lang.*;

public class ObjectToDouble{
  public static void main (String[] args){
  Object obj = 10;
  String str = obj.toString(); double d = Double.valueOf(str).doubleValue();
  System.out.println("Double value is: = " + d);  }
}

Download of this program:

Output of this program:

C:\corejava>java ObjectToDouble
Double value is: = 10.0
C:\corejava> _

Ads

Ads