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); } } |
Output of this program:
| C:\corejava>java ObjectToDouble Double value is: = 10.0 C:\corejava> _ |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Convert Object to Double
Post your Comment