Q: How can I round or slide a number to the nearest integer multiple of my choice? (For example rounding 13.3, 22.75 and 6 to the nearest 5 = 15, 25, 5 respectively)

This type of function is used when you have certain incremental values that you want to move real-world values into. It's often referred to as a snap-to or quantize function. In both implementations below, intNum is the number you're testing and intRn is the number that you want to move intNum to the nearest multiple of.

In VBScript:

<% Function RoundTo(intNum, intRn) RoundTo= Int((intNum / intRn)+.5) * intRn End Function %>

FAQ posted by Richard Lowe at
11/21/2000 1:17:45 PM to the
Math Functions category.
This FAQ has been viewed 53,456 times.

Do you have a FAQ you'd like to suggest?
Suggestions? Comments? If so, send it in!
Also, if you'd like to be a FAQ Admin (creating/editing FAQs),
let me know! If you are looking for other FAQs, be
sure to check out the 4Guys
FAQ and Commonly Asked Messageboard Questions!