Skip to content

Convert Float object to numeric primitive types Example

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

How to convert Float object to numeric primitive types in Java?

Use the xxxValue method of the Float wrapper class to convert Float object to primitive numeric types where xxx is the primitive type you want to convert to as given below.

1) Convert Float to byte

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

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

2) Convert Float to short

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

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

3) Convert Float to int

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

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

4) Convert Float to long

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

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

5) Convert Float to float

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

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

6) Convert Float to double

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

This method returns the value of the Float 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.