@jossmac/lil-libs
    Preparing search index...

    Function roundToStep

    • Rounds a number to the nearest step interval.

      Works on the decimal values as written, so results are free of floating-point noise and halfway values are detected exactly. Halfway values round away from zero.

      • value: number

        Number to round.

      • step: number

        Interval to snap to; must be finite and non-zero. The sign is ignored.

      The nearest multiple of step to value, at the decimal precision of step. Values too large to be affected by step are returned unchanged.

      roundToStep(5.26, 0.25); // 5.25
      roundToStep(-5.26, 0.25); // -5.25
      roundToStep(0.35, 0.1); // 0.4

      When step is 0, or fails the isFiniteNumber guard.