Float parseFloat() method in Java with examples Last Updated : 26 Oct, 2018 Comments Improve Suggest changes Like Article Like Report The parseFloat() method in Float Class is a built in method in Java that returns a new float initialized to the value represented by the specified String, as done by the valueOf method of class Float. Syntax: public static float parseFloat(String s) Parameters: It accepts a single mandatory parameter s which specifies the string to be parsed. Return type: It returns e float value represented by the string argument. Exception: The function throws two exceptions which are described below: NullPointerException- when the string parsed is null NumberFormatException- when the string parsed does not contain a parsable float Below is the implementation of the above method. Program 1: Java // Java Code to implement // parseFloat() method of Float class class GFG { // Driver method public static void main(String[] args) { String str = "100"; // returns the float value // represented by the string argument float val = Float.parseFloat(str); // prints the float value System.out.println("Value = " + val); } } Output: Value = 100.0 Program 2: To show NumberFormatException Java // Java Code to implement // parseFloat() method of Float class class GFG { // Driver method public static void main(String[] args) { try { String str = ""; // returns the float value // represented by the string argument float val = Float.parseFloat(str); // prints the float value System.out.println("Value = " + val); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: Exception: java.lang.NumberFormatException: empty String Program 3: To show NullPointerException Java // Java Code to implement // parseFloat() method of Float class class GFG { // Driver method public static void main(String[] args) { try { String str = null; // returns the float value // represented by the string argument float val = Float.parseFloat(str); // prints the float value System.out.println("Value = " + val); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: Exception: java.lang.NullPointerException Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#parseFloat(java.lang.String) Comment More infoAdvertise with us Next Article Float parseFloat() method in Java with examples G gopaldave Follow Improve Article Tags : Java java-basics Java-lang package Java-Functions Java-Float +1 More Practice Tags : Java Similar Reads Field setFloat() method in Java with Examples setFloat() method of java.lang.reflect.Field used to set the value of a field as a float on the specified object. When you need to set the value of a field of an object as a float then you can use this method to set value over an Object. Syntax: public void setFloat(Object obj, float f) throws Illeg 3 min read Float shortValue() method in Java with examples The shortValue() method in Float Class is a built-in method in Java which returns the value specified by calling the object as short after typecasting.Syntax: public short shortValue() Return Value: It return the value of FloatObject as short.Below programs illustrate shortValue() method in Java: Pr 2 min read Short floatValue() method in Java with Example The java.lang.Short.floatValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a float. Syntax: public float floatValue() Return type: It return the value of ShortObject as float. Below is the implementation of floatValue() method in Java 2 min read PrintStream print(float) method in Java with Examples The print(float) method oPrintStream Class in Java is used to print the specified float value on the stream. This float value is taken as a parameter. Syntax: public void print(float floatValue) Parameters: This method accepts a mandatory parameter floatValue which is the float value to be written o 2 min read PrintStream println(float) method in Java with Examples The println(float) method of PrintStream Class in Java is used to print the specified float value on the stream and then break the line. This float value is taken as a parameter. Syntax: public void println(float floatValue) Parameters: This method accepts a mandatory parameter floatValue which is t 2 min read Like