roundWithThreshold()
ts
function roundWithThreshold(value, threshold): number;Defined in: math/round.ts:19
Rounds a number to the nearest integer using a custom fractional threshold instead of the standard 0.5.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | number to round. |
threshold | number | Fractional threshold at which rounding switches from floor to ceil. Typically between 0 and 1. |
Returns
number
The rounded integer result according to the provided threshold.
Example
ts
console.assert(Math.roundWithThreshold(1.5, 0.3) === 2)
console.assert(Math.roundWithThreshold(1.2, 0.3) === 1)Since
1.0.0
Author
Ian Wenneckers