Java Program to convert a String to a float type Number


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.

Example

 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);
   }
}

Output

Float: 111.8

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

136 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements