1// truncate function
2// in this example the default value is 2
3function truncate(number, index = 2) {
4 // cutting the number
5 return +number.toString().slice(0, (number.toString().indexOf(".")) + (index + 1));
6}
7
8// example
9console.log(truncate(1234.56789, 3)); // 1234.567
10