roundToStep
Round a number to a step. Accepts an interval and optional offset.
const rounded = roundToStep(45, { offset: 20, interval: 10 })
console.log(rounded) // 50
const rounded = roundToStep(45, { offset: 20, interval: 10, direction: 'down' })
console.log(rounded) // 40
Options
Option | Default | Description |
---|---|---|
offset | 0 | The start of the series |
interval | 1 | The distance between the numbers |
direction | commercial |
up , down or commercial
|
How to use
npm install round-to-step
import { roundToStep } from 'round-to-step'