I have the number 0.6720505101642719
I would like to make It 0.6720
while .toFixed(4)
returns 0.6721
and slicing the number as string won't work as well
const modifyDecimal = (number, decimalCount) => {
const parts = number.toString().split('.');
const limitedDecimal = parts[1].slice(0, decimalCount);
return Number(`${parts[0]}.${limitedDecimal}`);
}
modifyDecimal(0.6720505101642719, 4)
// 0.672 missing the 0 here