Home Tutorial Java Corejava Dataconversion String Conversion from String to float

 
 

Conversion from String to float
Posted on: September 3, 2010 at 12:00 AM
In this tutorial we will learn how to convert a string type data to float type data.

Conversion from String to float:

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

Description:

This program will take a String value from mystring variable. The line float myfloat = Float.parseFloat(mystring); converts the mystring string type value to myfloat float type value. The parseFloat() method coverts the any type data to float type data.

Code:

class Stringtofloat {
	public static void main(String[] args) {
		try {
			String mystring = "1.4";
			float myfloat = Float.parseFloat(mystring);
			System.out.println("Converted value from String to float is: "
					+ myfloat);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
};
 

Output:

Download this code

Related Tags for Conversion from String to float:


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.