Home Java Java-conversion Convert String To Double



Convert String To Double
Posted on: July 5, 2007 at 12:00 AM
In this section, we are going to convert a numeric type string value into a double.

Convert String To Double

     

In this section, we are going to convert a numeric type string value into a double. The double supports big-integer value. 

Code Description:

This program simply takes a numeric type string at the console with the "Enter numeric type string value:" message and it converts into a double. The doubleValue() method returns the double value of this double object. And Double class wraps a value of the primitive type double in an object. Finally, it we get the value to be converted into a double.

Here is this the code of this program:

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

public class StringToDouble{
  public static void main (String[] argsthrows IOException{
  BufferedReader bff= new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter numeric type string value:");
  String num = bff.readLine();
  try{
  double d = Double.valueOf(num.trim()).doubleValue();
  System.out.println("double d = " + d);
  }
  catch (NumberFormatException e){
  System.out.println("NumberFormatException: " + e.getMessage());
  }
  }
}

Download this program:

Output of this program given below.

C:\corejava>java StringToDouble
Enter string value:
23
double d = 23.0
C:\corejava>

Related Tags for Convert String To Double:
cstringclassconsoleobjectconvertmethodtypedoublevalueevalreturnoleintthismessagewrapprimitivewithnumericprogramtorameitmitpeimenterinasmntpstrsagejclesagemeintoobjprodosurnssasoessatplykisivmplandconsstrrtrtssasimwrapsvassriringthstapaluevaevajeplprmindonogrolo


More Tutorials from this section

Ask Questions?    Discuss: Convert String To Double  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

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.