You can achieve this through different ways. Few are:
1. using
.toFixed()
let num = 5.567891;
let n = num.toFixed(4);
parseFloat("5.567891").toFixed(4);
Refer:
JavaScript toFixed() Method[
^]
2. using
Math.round()
console.log(Math.round(5.95123*10000)/10000);
Refer:
Math.round() - JavaScript | MDN[
^]
Above two should be good enough to achieve most cases. Not suggesting using
Number.EPSILON
for now. Though if you need precision rounding off, you can refer to:
Number.EPSILON - JavaScript | MDN[
^]