Float.valueOf(): This method is available in java.lang.Float class of Java.
Syntax:
Float java.lang.Float.valueOf(String s) throws NumberFormatException
This method takes one argument of type String as its parameter. This method returns a Float object holding the float value represented by the argument string s.
Note: If s is null, then a NullPointerException is thrown.
Parameters: One parameter is required for this method.
s: the string to be parsed.
Returns: a Float object holding the value represented by the String argument.
Throws: NumberFormatException - if the string does not contain a parsable number.
For Example:
String s = "1818.56"
Float.valueOf(s) = > It returns 1818.56
Approach
Java
public class FloatValueofString {public static void main(String[] args) {String s = "1818.56";System.out.println(Float.valueOf(s));}}
Output:
1818.56
No comments:
Post a Comment