.NET method to round a number up to the nearest multiple of another number

netrounding

I'm looking for a method that can round a number up to the nearest multiple of another. This is similar Quantization.

Eg. If I want to round 81 up to the nearest multiple of 20, it should return 100.

Is there a method built-in method in the .NET framework I can use for this?

The reason I'm asking for a built-in method is because there's a good chance it's been optimized already.

Best Answer

Yes, integer arithmetic.

To round m up to the next multiple of n, use ((m+n-1)/n)*n