round-decimal
Version:
Decimal rounding with ULP.
22 lines (21 loc) • 470 B
JavaScript
function o(t) {
return Math.pow(2, Math.ceil(Math.log2(Math.abs(t))) - 52);
}
function r(t) {
return Math.trunc(Math.abs(Math.log10(o(t))));
}
const c = 3;
function s(t, a = c) {
const i = r(t);
if (i < a)
return t;
const n = t < 0 ? -Math.pow(10, i) : Math.pow(10, i);
return Math.round(t * n) / n;
}
export {
o as approximateUlp,
s as default,
c as defaultMinSignificantFractionDigits,
r as getSignificantFractionDigits,
s as roundDecimal
};