To convert
float
to int
in Java, do this: (int)Math.round(floatValue)
.Here's how you do it:
float floatNumber = 1.534f;
int intNumber = (int)Math.round(floatNumber);
System.out.println(intNumber); // 2
Without rounding
If you want to convert without rounding, then here's how you do it:
float floatNumber = 1.534f;
int intNumber = (int)floatNumber;
System.out.println(intNumber); // 1
// …or without a variable
System.out.println((int)floatNumber); // 1