Arrotondare un numero ad un multiplo in Java

From RVM Wiki
Jump to navigation Jump to search
x = 475;
int m = (x/10)+1;
int rounded = m*10

Divide the number by 10 to get the number of tens, we only want the integer part.

We add 1 to make up for the fractional bit then multiply that by 10.

Of course, that method would return 490 if x = 480.

It'd always be 10 off for any number thats already a multiple of 10.

So check if its a multiple first by using modulus.

http://forums.devx.com/archive/index.php/t-153730.html