-
Notifications
You must be signed in to change notification settings - Fork 0
round
Subhajit Sahu edited this page Aug 9, 2022
·
6 revisions
Round a number to specific precision.
function round(x, pre)
// x: a number
// pre: to precision [1]
const xnumber = require('extra-number');
xnumber.round(9.135, 1);
// → 9
xnumber.round(9.135, 1e-2);
// → 9.14
xnumber.round(9.1357, 0.05);
// → 9.15
0.1 + 0.2
// → 0.30000000000000004 (why?)
xnumber.round(0.1 + 0.2, 1e-12);
// → 0.3 (nice!)