BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Java String to float Conversion

Last Updated: November 8, 2022 by Chaitanya Singh | Filed Under: java

In this guide, we will see how to convert String to float in Java. We will use the parseFloat() method of Float class for this conversion.

public static float parseFloat(String str)

This method takes string argument and returns a float number represented by the argument str.

Program to Convert String to float

public class JavaExample{
  public static void main(String args[]){
    String str = "15.6515";
    float floatNum = Float.parseFloat(str);
    System.out.println("String to float: "+floatNum);
  }
}

Output: