Share on Google+Share on Google+

Convert Object to 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.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> _


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

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Convert Object to Double  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
April 24, 2012

thanks a lot