Convert Float to byte, double, float, int, long and short

ReturnMethodSummary
bytebyteValue()Returns the value of this Float as a byte (by casting to a byte).
doubledoubleValue()Returns the double value of this Float object.
floatfloatValue()Returns the float value of this Float object.
intintValue()Returns the value of this Float as an int (by casting to type int).
longlongValue()Returns value of this Float as a long (by casting to type long).
shortshortValue()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
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.