
Returns a
Float object holding the
float value represented by the argument string
s.
If s is null, then a
NullPointerException is thrown.
Leading and trailing whitespace characters in s
are ignored. Whitespace is removed as if by the String.trim() method; that is, both ASCII space and control
characters are removed. The rest of s should
constitute a FloatValue as described by the lexical
syntax rules:
- FloatValue:
- Signopt
NaN
- Signopt
Infinity
- Signopt FloatingPointLiteral
- Signopt HexFloatingPointLiteral
- SignedInteger
- HexFloatingPointLiteral:
- HexSignificand BinaryExponent FloatTypeSuffixopt
- HexSignificand:
- HexNumeral
- HexNumeral
.
0x HexDigitsopt
. HexDigits
0X HexDigitsopt
. HexDigits
- BinaryExponent:
- BinaryExponentIndicator SignedInteger
- BinaryExponentIndicator:
p
P
where
Sign,
FloatingPointLiteral,
HexNumeral,
HexDigits,
SignedInteger and
FloatTypeSuffix are as defined in the lexical structure
sections of the of the
Java Language
Specification. If
s does not have the form of
a
FloatValue, then a
NumberFormatException
is thrown. Otherwise,
s is regarded as
representing an exact decimal value in the usual
"computerized scientific notation" or as an exact
hexadecimal value; this exact numerical value is then
conceptually converted to an "infinitely precise"
binary value that is then rounded to type
float
by the usual round-to-nearest rule of IEEE 754 floating-point
arithmetic, which includes preserving the sign of a zero
value. Finally, a
Float object representing this
float value is returned.
To interpret localized string representations of a
floating-point value, use subclasses of NumberFormat.
Note that trailing format specifiers, specifiers that
determine the type of a floating-point literal
(1.0f is a float value;
1.0d is a double value), do
not influence the results of this method. In other
words, the numerical value of the input string is converted
directly to the target floating-point type. In general, the
two-step sequence of conversions, string to double
followed by double to float, is
not equivalent to converting a string directly to
float. For example, if first converted to an
intermediate double and then to
float, the string
"1.00000017881393421514957253748434595763683319091796875001d"
results in the float value
1.0000002f; if the string is converted directly to
float, 1.0000001f results.
To avoid calling this method on an invalid string and having
a NumberFormatException be thrown, the documentation
for Double.valueOf lists a regular
expression which can be used to screen the input.
Returns:
a Float object holding the value
represented by the String argument.
Parameters:
- s - the string to be parsed.
Throws:
- NumberFormatException - if the string does not contain a
parsable number.