Conversion from String to double

In this tutorial we will learn how to convert a string type data to double type data.

 
 

Share on Google+Share on Google+

Conversion from String to double

Ads

In this tutorial we will learn how to convert a string type data to double type data.

Conversion from String to double:

In this tutorial we will learn how to convert a string type data to double type data.

Description:

This program will take a String value from mystring variable. The line double mydouble = Double.parseDouble(mystring); converts the mystring string type value to mydouble double type value. The parseDouble() method coverts any type data to double type data.

Code:

class Stringtodouble {
	public static void main(String[] args) {
		try {
			String mystring = "1.4123456789";
			double mydouble = Double.parseDouble(mystring);
			System.out.println("Converted value from String to double is: "
					+ mydouble);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
};
 

Output:

Download this code

Advertisements

Ads

Posted on: September 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles