Reputation:
How to round an integer in javascript to its previous decimal.
Ex.:
15 to 10.
16 to 10.
21 to 20.
29 to 20.
Upvotes: 0
Views: 71
Reputation: 137
you can create your own function to do that
function intFloor(num){
let temp = num%10;
return num-temp;
}
console.log(intFloor(15));
if you know prototype You can add this to prototype
Number.prototype.intFloor = function(){
let temp = this%10;
return this - temp;
}
console.log((52).intFloor()) // result 50
Upvotes: 0
Reputation: 7299
Can even use Math.floor()
var num = 24;
var round = Math.floor(num / 10) * 10;
console.log(round)
Upvotes: 2