Search code examples
c#.netmath

How to round a integer to the close hundred?


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#?


Solution

  • Try the Math.Round method. Here's how:

    Math.Round(76d / 100d, 0) * 100;
    Math.Round(121d / 100d, 0) * 100;
    Math.Round(9660d / 100d, 0) * 100;