int to float Java

int to float Java


After knowing primitive data types and Java rules of Data Type Casting (Type Conversion), let us cast int to float.

The int and float, each takes 4 bytes of memory. The int holds a whole number and float holds a floating-point number. Assignment of int to float is done automatically by JVM.

byte –> short -> int –> long –> float –> double

The left-side value can be assigned to any right-side value and is done implicitly. The reverse like float to int requires explicit casting.

Examples of implicit casting

int i1 = 10;
long l1 = i1;

byte x = 10;
short y = x;

Following program on int to float explains implicit casting. Observe, Java style where int is automatically assigned to float.


int to float
Output screenshot of int to float Java

float f1 = i1;

As int value i1 is assigned to float f1, the whole number is converted into floating-point value 10.0.

View all for 65 types of Conversions

Leave a Reply

Your email address will not be published. Required fields are marked *