Q:

Java String to float

belongs to collection: Java Conversion Programs

0

We can convert String to float in java using Float.parseFloat() method.

Scenario

It is generally used if we have to perform mathematical operations on the string that contains float number. Whenever we get data from textfield or textarea, entered data is received as a string. If entered data is float, we need to convert string to float. To do so, we use Float.parseFloat() method.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Signature

The parseFloat() is the static method of Float class. The signature of parseFloat() method is given below:

 

public static int parseFloat(String s)  

Java String to float Example

Let's see the simple code to convert string to float in java.

 

float f=Float.parseFloat("23.6");  

Let's see the simple example of converting String to float in java.

public class StringToFloatExample{  
public static void main(String args[]){  
String s="23.6";  
float f=Float.parseFloat("23.6");  
System.out.println(f);  
}}  

 

Output:

23.6

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Convert float to String... >>
<< Java long to String...