Java Program to convert Java String to Float Object


To convert String to Float Object, you can use a method Float.valueOf() method or you can even achieve this without using the in-built method.

Let us see both the examples.

The following is an example that converts String to Float Object using Float.valueOf() method.

Example

 Live Demo

public class Demo {
   public static void main(String args[]) {
      Float f = Float.valueOf("30.67");
      System.out.println(f);
   }
}

Output

30.67

Let us see another example.

Example

 Live Demo

public class Demo {
   public static void main(String args[]) {
      Float f = new Float("45.88");
      System.out.println(f);
   }
}

Output

45.88

Updated on: 26-Jun-2020

144 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements