Categories
Coding

Rounding to nearest X

An interesting forumla to remember for rounding numbers to the nearest X.

Int32 value = 43.7;
Int32 toNearest = 5;
Int32 result = Math.Round(value / toNearest) * toNearest;

Leave a Reply

Your email address will not be published. Required fields are marked *