@extra-number/round
v2.0.27
Published
Rounds number to specific precision.
Downloads
304
Readme
Rounds number to specific precision.
Also helps to deal with number precision problems. This is part of package extra-number.
number.round(n, [pre]);
// n: a number
// pre: to precision (1e-12)
const number = require('extra-number');
/* 1. round to specific precision */
number.round(9.135, 1);
// 9
number.round(9.135, 1e-2);
// 9.14
number.round(9.1357, 0.05);
// 9.15
/* 2. round precision errors */
0.1*0.2
// 0.020000000000000004
number.round(0.1*0.2);
// 0.02