Java Program to convert a String to a float type Number

Java 8Object Oriented ProgrammingProgramming

Use the parseFloat() method in Java to convert a String to a float type.

Let’s say we have the following string.

String str = "111.8";

Now, the Float.parseFloat() method will convert it to a float type number.

float floatVal = Float.parseFloat(str);

The following is the complete example with output.


 Live Demo

public class Demo {
   public static void main(String args[]) {
      String str = "111.8";
      float floatVal = Float.parseFloat(str);
      System.out.println("Float: "+floatVal);


Float: 111.8
Updated on 26-Jun-2020 08:47:30