Convert long value to byte, double, float, int, long, short

ReturnMethodSummary
bytebyteValue()Returns the value of this Long as a byte.
doubledoubleValue()Returns the value of this Long as a double.
floatfloatValue()Returns the value of this Long as a float.
intintValue()Returns the value of this Long as an int.
longlongValue()Returns the value of this Long as a long value.
shortshortValue()Returns the value of this Long as a short.

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

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

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

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

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

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

The output:


byte:-121
short:-10617
int:1234567
float1234567.0
double:1234567.0
long:1234567
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.