Arrotondare un numero ad un multiplo in Java: Difference between revisions
Jump to navigation
Jump to search
m New page: 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 multip... |
(No difference)
|
Latest revision as of 17:37, 19 May 2010
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.