Convert Object to Double

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

Ads

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> _

Advertisements

Share on Google+Share on Google+

Convert Object to Double

Posted on: March 18, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Convert Object to Double  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
dong
April 24, 2012
wow

thanks a lot

Ads

 

Ads