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  

Float:
  1. Float class
  2. MAX/MIN_VALUE Find out the Maximum value and Minimum value a float type can have
  3. Create a Float object
  4. Convert Float to byte, double, float, int, long and short
  5. Compare two float objects
  6. Infinite and Not A Number
  7. Convert float value to Hex String value
  8. Convert float value to String value
  9. Convert string value to float value
  10. Bit oriented calculation for float