Sunday 23 December 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...