Convert Java String to Float

We often have to extract some text that is a number. To perform some operations on that number, we must first convert it to the appropriate type. In this post, you will learn how to convert Java String to float data type.

You can use the Float.parseFloat() method to parse Java String to float.

public static int parseFloat(String s)

Convert Java String to Float example

class Test {

  public static void main(String[] args) {

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

    System.out.println(f);
  }
}
Output: 102.4
 
That’s all about how to can convert String to float in Java. In the next lesson, we will cover converting float to String.
 
Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *