I don't know it my nomenclature is correct! Anyway, these are the integer I have, for example :
76
121
9660
And I'd like to round them to the close hundred, such as they must become :
100
100
9700
How can I do it faster in C#? I think about an algorithm, but maybe there are some utilities on C#?
Just some addition to @krizzzn's accepted answer...
Do note that the following will return 0:
Consider using the following and make it return 100 instead:
Depending on what you're doing, using decimals might be a better choice (note the m):
I wrote a simple extension method to generalize this kind of rounding a while ago:
It leverages integer division to find the closest rounding.
Example use:
And in your example: