Skip to content

Convert Double object to numeric primitive types Example

This example shows how to convert Double object to a numeric primitive types byte, short, int, long, float, double.

How to convert a Double object to numeric primitive types in Java?

We can use the xxxValue method of the Double wrapper class to convert a Double object to primitive numeric types, where the xxx is the primitive type we want to convert to as given below.

1) Convert Double to byte

Use the byteValue method of Double wrapper class to convert from Double to byte primitive value.

This method returns the value of the Double object as a byte primitive.

2) Convert Double to short

Use the shortValue method of Double wrapper class to convert from Double to a short primitive value.

This method returns the value of the Double object as a short primitive.

3) Convert Double to int

Use the intValue method of Double wrapper class to convert from Double to int primitive value.

This method returns the value of the Double object as an int primitive.

4) Convert Double to long

Use the longValue method of Double wrapper class to convert from Double to long primitive value.

This method returns the value of the Double object as a long primitive.

5) Convert Double to float

Use the floatValue method of Double wrapper class to convert from Double to float primitive value.

This method returns the value of the Double object as a float primitive.

6) Convert Double to double

Use the doubleValue method of Double wrapper class to convert from Double to double primitive value.

This method returns the value of the Double object as a double primitive.

Example

Output

This example is a part of the Java Basic Examples and Java Type conversion Tutorial.

Please let me know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.