Skip to content

Instantly share code, notes, and snippets.

@jefsnare
Created March 23, 2016 06:28
Show Gist options
  • Save jefsnare/70b8ca09788efa4f30f3 to your computer and use it in GitHub Desktop.
Save jefsnare/70b8ca09788efa4f30f3 to your computer and use it in GitHub Desktop.
let roundUpValueByStep = (value, step) => {
return Math.ceil(value * (1 / step)) / (1 / step);
}
console.log(roundUpValueByStep(1.25, 0.5)); // 1.5
console.log(roundUpValueByStep(1.77, 0.5)); // 2
console.log(roundUpValueByStep(1, 0.5)); // 1
console.log(roundUpValueByStep(2.1, 0.25)); // 2.25
console.log(roundUpValueByStep(2.45, 0.25)); // 2.5
console.log(roundUpValueByStep(2.67, 0.25)); //2.75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment