I want to keep the decimals, I have a long number 120.29998999867869
and I want to cut it with 5 decimal places, the desired result is 120.299998
, I try the following code but I get120.30000
let num = 120.29999999867869;
console.log(num.toFixed(5));
In the example that you are giving, the rounding is done towards
.30000
since it is not the same number that you raise in the question.If you want the decimals to be seen without rounding, you can do the following:
However, it is a not so attractive solution .
I include examples: