Java Float valueOf() MethodThe valueOf() method of Java Float class returns a float instance representing the specified float value 'f' or string argument 's'. Syntax:Parameters:
Return Value:The valueOf() method returns the float object of the specified float or String value passed. Example 1Output: 1. Value = 4.8654684E7 2. Value = -6789.87 3. Value = 0.0988767 Example 2Output: Enter your pin code : 121002 121002.0 Area = Faridabad. Example 3Output: 1. Value = Infinity 2. Value = -Infinity 3. Value = 1.17549435E-38 4. Value = 3.4028235E38 5. Value = 1.4E-45 6. Value = NaN Example 4Output: Enter string value: reema Exception in thread "main" java.lang.NumberFormatException: For input string: "reema" at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122) at java.lang.Float.parseFloat(Float.java:451) at java.lang.Float.valueOf(Float.java:416) at Float_valueOfMethodExample4.main(Float_valueOfMethodExample4.java:8) It will give us run time error because string value reema can't be converted to Float, so this run time exception should be checked. Next TopicJava float longvalue method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India