| public final class java.lang Float
|
Java SE 6 |
Float class wraps a value of primitive type
float in an object. An object of type
Float contains a single field whose type is
float.
In addition, this class provides several methods for converting a
float to a String and a
String to a float, as well as other
constants and methods useful when dealing with a
float.
| version | 1.101, 04/07/06 |
| since | JDK1.0 |
| Fields | |||
|---|---|---|---|
| final public static float | POSITIVE_INFINITY A constant holding the positive infinity of type float. It is equal to the value returned by
Float.intBitsToFloat(0x7f800000).
| ||
| final public static float | NEGATIVE_INFINITY A constant holding the negative infinity of type float. It is equal to the value returned by
Float.intBitsToFloat(0xff800000).
| ||
| final public static float | NaN A constant holding a Not-a-Number (NaN) value of type float. It is equivalent to the value returned by
Float.intBitsToFloat(0x7fc00000).
| ||
| final public static float | MAX_VALUE A constant holding the largest positive finite value of type float, (2-2-23)·2127.
It is equal to the hexadecimal floating-point literal
0x1.fffffeP+127f and also equal to
Float.intBitsToFloat(0x7f7fffff).
| ||
| final public static float | MIN_NORMAL A constant holding the smallest positive normal value of type float, 2-126. It is equal to the
hexadecimal floating-point literal 0x1.0p-126f and also
equal to Float.intBitsToFloat(0x00800000).
| ||
| final public static float | MIN_VALUE A constant holding the smallest positive nonzero value of type float, 2-149. It is equal to the
hexadecimal floating-point literal 0x0.000002P-126f
and also equal to Float.intBitsToFloat(0x1).
| ||
| final public static int | MAX_EXPONENT Maximum exponent a finite float variable may have. It
is equal to the value returned by Math.getExponent(Float.MAX_VALUE).
| ||
| final public static int | MIN_EXPONENT Minimum exponent a normalized float variable may have.
It is equal to the value returned by Math.getExponent(Float.MIN_NORMAL).
| ||
| final public static int | SIZE The number of bits used to represent a float value.
| ||
| final public static Class | TYPE The Class instance representing the primitive type
float.
| ||
| Constructors | |||||||
|---|---|---|---|---|---|---|---|
| public | Float(float value) Constructs a newly allocated Float object that
represents the primitive float argument.
| ||||||
| public | Float(double value) Constructs a newly allocated Float object that
represents the argument converted to type float.
| ||||||
| public | Float(String s) throws NumberFormatException Constructs a newly allocated Float object that
represents the floating-point value of type float
represented by the string. The string is converted to a
float value as if by the valueOf method.
| ||||||
| Methods | |||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public byte | byteValue() Returns the value of this Float as a
byte (by casting to a byte).
| ||||||||||||||||||||||||||||
| public static int | compare(float f1, float f2) Compares the two specified float values. The sign
of the integer value returned is the same as that of the
integer that would be returned by the call:
new Float(f1).compareTo(new Float(f2))
| ||||||||||||||||||||||||||||
| public int | compareTo(Float anotherFloat) Compares two Float objects numerically. There are
two ways in which comparisons performed by this method differ
from those performed by the Java language numerical comparison
operators (<, <=, ==, >= >) when
applied to primitive float values:
| ||||||||||||||||||||||||||||
| public double | doubleValue() Returns the double value of this
Float object.
| ||||||||||||||||||||||||||||
| public boolean | equals(Object obj) Compares this object against the specified object. The result is true if and only if the argument is not
null and is a Float object that
represents a float with the same value as the
float represented by this object. For this
purpose, two float values are considered to be the
same if and only if the method #floatToIntBits(float)
returns the identical int value when applied to
each.
Note that in most cases, for two instances of class
f1.floatValue() == f2.floatValue()
also has the value
| ||||||||||||||||||||||||||||
| public static int | floatToIntBits(float value) Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout.
Bit 31 (the bit that is selected by the mask
If the argument is positive infinity, the result is
If the argument is negative infinity, the result is
If the argument is NaN, the result is
In all cases, the result is an integer that, when given to the
| ||||||||||||||||||||||||||||
| public static int | floatToRawIntBits(float value) Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, preserving Not-a-Number (NaN) values.
Bit 31 (the bit that is selected by the mask
If the argument is positive infinity, the result is
If the argument is negative infinity, the result is
If the argument is NaN, the result is the integer representing
the actual NaN value. Unlike the
In all cases, the result is an integer that, when given to the
| ||||||||||||||||||||||||||||
| public float | floatValue() Returns the float value of this Float
object.
| ||||||||||||||||||||||||||||
| public int | hashCode() Returns a hash code for this Float object. The
result is the integer bit representation, exactly as produced
by the method #floatToIntBits(float), of the primitive
float value represented by this Float
object.
| ||||||||||||||||||||||||||||
| public static float | intBitsToFloat(int bits) Returns the float value corresponding to a given
bit representation.
The argument is considered to be a representation of a
floating-point value according to the IEEE 754 floating-point
"single format" bit layout.
If the argument is
If the argument is
If the argument is any value in the range
In all other cases, let s, e, and m be three values that can be computed from the argument:
Then the floating-point result equals the value of the mathematical
expression s·m·2e-150.
Note that this method may not be able to return a
| ||||||||||||||||||||||||||||
| public int | intValue() Returns the value of this Float as an
int (by casting to type int).
| ||||||||||||||||||||||||||||
| public long | longValue() Returns value of this Float as a long
(by casting to type long).
| ||||||||||||||||||||||||||||
| public static float | parseFloat(String s) throws NumberFormatException Returns a new float initialized to the value
represented by the specified String, as performed
by the valueOf method of class Float.
| ||||||||||||||||||||||||||||
| public short | shortValue() Returns the value of this Float as a
short (by casting to a short).
| ||||||||||||||||||||||||||||
| public static String | toHexString(float f) Returns a hexadecimal string representation of the float argument. All characters mentioned below are
ASCII characters.
| ||||||||||||||||||||||||||||
| public static String | toString(float f) Returns a string representation of the float
argument. All characters mentioned below are ASCII characters.
float. That is, suppose that x is the
exact mathematical value represented by the decimal
representation produced by this method for a finite nonzero
argument f. Then f must be the float
value nearest to x; or, if two float values are
equally close to x, then f must be one of
them and the least significant bit of the significand of
f must be 0.
To create localized string representations of a floating-point
value, use subclasses of
| ||||||||||||||||||||||||||||
| public String | toString() Returns a string representation of this Float object.
The primitive float value represented by this object
is converted to a String exactly as if by the method
toString of one argument.
| ||||||||||||||||||||||||||||
| public static Float | valueOf(String s) throws NumberFormatException Returns a Float object holding the
float value represented by the argument string
s.
If Leading and trailing whitespace characters in 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 Note that trailing format specifiers, specifiers that
determine the type of a floating-point literal
( To avoid calling this method on an invalid string and having
a
| ||||||||||||||||||||||||||||
| public static Float | valueOf(float f) Returns a Float instance representing the specified float value. If a new Float instance is not required, this method should generally be used in preference to the constructor #Float(float), as this method is likely to yield
significantly better space and time performance by caching
frequently requested values.
| ||||||||||||||||||||||||||||
| About DocWeb · Bundles · Export · Export All | Top 10 · Statistics · Login |
| About Sun · Contact · Privacy · Terms of Use · Trademarks | Java SE 6 · Copyright © 1994-2009 Sun Microsystems, Inc.All rights reserved. Use is subject to license terms |
![]() |
![]() |
|