Convert Float to byte, double, float, int, long and short
byte byteValue()
- Returns the value of this Float as a byte (by casting to a byte).
double doubleValue()
- Returns the double value of this Float object.
float floatValue()
- Returns the float value of this Float object.
int intValue()
- Returns the value of this Float as an int (by casting to type int).
long longValue()
- Returns value of this Float as a long (by casting to type long).
short shortValue()
- Returns the value of this Float as a short (by casting to a short).
public class Main {
public static void main(String[] args) {
Float floatObject = new Float("10.01");
byte b = floatObject.byteValue();
System.out.println("byte:"+b);
short s = floatObject.shortValue();
System.out.println("short:"+s);
int i = floatObject.intValue();
System.out.println("int:"+i);
float f = floatObject.floatValue();
System.out.println("float"+f);
double d = floatObject.doubleValue();
System.out.println("double:"+d);
long l = floatObject.longValue();
System.out.println("long:"+l);
}
}
The output:
byte:10
short:10
int:10
float10.01
double:10.010000228881836
long:10
Home
Java Book
Essential Classes
Java Book
Essential Classes
Float:
- Float class
- MAX/MIN_VALUE Find out the Maximum value and Minimum value a float type can have
- Create a Float object
- Convert Float to byte, double, float, int, long and short
- Compare two float objects
- Infinite and Not A Number
- Convert float value to Hex String value
- Convert float value to String value
- Convert string value to float value
- Bit oriented calculation for float