Return double value as byte, double, float, int, long, short

ReturnMethodSummary
bytebyteValue()Returns a byte (by casting to a byte).
doubledoubleValue()Returns the double value of this Double object.
floatfloatValue()Returns the float value of this Double object.
intintValue()Returns the value of this Double as an int (by casting to type int).
longlongValue()Returns the value of this Double as a long (by casting to type long).
shortshortValue()Returns the value of this Double as a short (by casting to a short).

public class Main {
  public static void main(String[] args) {
    Double doubleObject = new Double("10.01");
    byte b = doubleObject.byteValue();
    System.out.println("byte:"+b);

    short s = doubleObject.shortValue();
    System.out.println("short:"+s);

    int i = doubleObject.intValue();
    System.out.println("int:"+i);

    float f = doubleObject.floatValue();
    System.out.println("float"+f);

    double d = doubleObject.doubleValue();
    System.out.println("double:"+d);

    long l = doubleObject.longValue();
    System.out.println("long:"+l);
  }
}

The output:


byte:10
short:10
int:10
float10.01
double:10.01
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.