To round down
console.log(1.0789.toFixed(2)); // 1.08
To trim
function trim(number, precision){
var array = number.toString().split(".");
array.push(array.pop().substring(0, precision));
var trimmedNumber = array.join(".");
console.log(trimmedNumber);
}
trim(1.0789, 2); //1.07
No comments:
Post a Comment