MCPcopy
hub / github.com/autoNumeric/autoNumeric / roundToNearest

Method roundToNearest

src/AutoNumericHelper.js:855–865  ·  view source on GitHub ↗

* Return the 'nearest rounded' value, according to the given step size. * @example roundToNearest(264789, 10000)) => 260000 * * @param {number} value * @param {number} [stepPlace=1000] Rounding step size (optional, default: 1000) * @returns {number}

(value, stepPlace = 1000)

Source from the content-addressed store, hash-verified

853 * @returns {number}
854 */
855 static roundToNearest(value, stepPlace = 1000) {
856 if (0 === value) {
857 return 0;
858 }
859
860 if (stepPlace === 0) {
861 this.throwError('The `stepPlace` used to round is equal to `0`. This value must not be equal to zero.');
862 }
863
864 return Math.round(value / stepPlace) * stepPlace;
865 }
866
867 /**
868 * Return the 'nearest rounded' value by automatically adding or subtracting the calculated offset to the initial value.

Callers 2

Calls 1

throwErrorMethod · 0.95

Tested by

no test coverage detected