Couldnt think of a better title. Well the problem is: I have the "int i", it can be any value. my goal is to transform the "int i" to the closest number divisible by 16.
For example, I got i = 33. Then i will be turned to 32 (16x2).But if I get i = 50, then it will be turned to 48 (16x3).
I tried many things for example:
for (int x = i; x < 999; x++){
if ( (i - x)/16 *is an integer*){
i = i - x;
}
But I dont know how to check if its an integer. So maybe my previous code work, but I just need to find a way to check if its an integer or a float. So.. any help is appreciated.
Use the mod operator. Mod gives you the remainder of a division operation.
public boolean isEvenlyDivisable(int a, int b) {
return a % b == 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With