How to convert String to Float in Java

Here we are going to see how we can convert a string value to float.

String to Float Conversion

String to float conversion in java is too easy. We can directly convert a String to float by using Float.parseFloat(String s) .

String s = "26.7";
float f = Float.parseFloat(s);

Let’s see a complete java program to convert string to float.

package gangforcode;

public class StringToFloat {
public static void main(String[] args) {
String s = "26.7";
float f = Float.parseFloat(s);

Float to String conversion

Similarly we can convert a float value into string by using Float.toString(float f). for more info you can check here

Similar Java Tutorial

Hello World –
data types in java –
identifiers in java –
keywords in java –
Multidimensional Array in Java –
Matrix Addition in Java –
Binary Search in Java –

Leave a Comment