I saw the algorithms in How do I find the next multiple of 10 of any integer?, and the one I came up with doesn't seem to match any of the answers in that post, so I'm wondering if there's an issue with what I came up with below:
if(n % 10 != 0)
{
return ((n / 10) + 1) * 10;
}
return n;
The conditional check is just in case n
is a decadel number (e.g., 10, 980, etc..), in which case we return the original number.
n / 10
gives us the truncated multiple of 10 (n
is an integer and n/10
performs integer division in the language I'm using (C++)), and then we simply add 1 to this and multiply by 10. Alternatively we could do n / 10 * 10 + 10