Skip to content

Instantly share code, notes, and snippets.

@samhernandez
samhernandez / round-to-nearest.js
Created May 30, 2013 16:59
Round a number to the nearest interval of a given number. (Because I always forget how darned simple this is.)
/**
* Returns the number rounded to the nearest interval.
* Example:
*
* roundToNearest(80, 100); // 100
* roundToNearest(25, 15); // 30
*
* @param {number} value The number to round
* @param {number} interval The numeric interval to round to
* @return {number}