UNPKG

als-statistics

Version:

Modular JS statistics toolkit for Node.js and the browser: descriptive stats, correlations (Pearson/Spearman/Kendall), t-tests & ANOVA (Student/Welch), reliability (Cronbach’s alpha), regression (linear/logistic), clustering (DBSCAN/HDBSCAN), and table/co

13 lines (12 loc) 449 B
export default function round(d, max = 8) { if (d === 0) return 0; if (d == null) return 0; const dd = Number(d); if (!Number.isFinite(dd)) return 0; // или dd, по договорённости const rounded = Math.trunc(dd); if (dd === rounded) return dd; let frac = Math.abs(dd - rounded), n = 0; while (frac && frac < 1 && n < max) { frac *= 10; n++; } // return Number(dd.toFixed(n)); return dd.toFixed(n); }