Sunday, December 23, 2018

javascript - How to round down number 2 decimal places?

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...