Skip to content
Subhajit Sahu edited this page Aug 8, 2022 · 1 revision

Round a number to specific precision.

Similar: floor, ceil, round.


function round(x, pre?)
// x:   a number
// pre: to precision [1]

const xmath = require('extra-math');


xmath.round(9.135, 1);
// → 9

xmath.round(9.135, 1e-2);
// → 9.14

xmath.round(9.1357, 0.05);
// → 9.15

0.1 + 0.2
// → 0.30000000000000004 (why?)

xmath.round(0.1 + 0.2, 1e-12);
// → 0.3 (nice!)


References

Clone this wiki locally