To convert
double
to int
in Java, do this: (int)Math.round(doubleValue)
.Here's how you do it:
double doubleNumber = 6.548f;
int intNumber = (int)Math.round(doubleNumber);
System.out.println(intNumber); // 7
Without rounding
If you want to convert without rounding, then here's how you do it:
double doubleNumber = 6.548f;
int intNumber = (int)doubleNumber;
System.out.println(intNumber); // 6
// …or without a variable
System.out.println((int)doubleNumber); // 6