Java Program to convert Java String to Float Object

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 10-Dec-2018 11:25:23
Advertisements