i want to round a decimal to like 1.5. here’s what i have:
<hr>Math.floor((smallNum/bigNum)*100)<hr>
is there something i can do to this so that it’ll round to like 11.5?
i want to round a decimal to like 1.5. here’s what i have:
<hr>Math.floor((smallNum/bigNum)*100)<hr>
is there something i can do to this so that it’ll round to like 11.5?
here’s a function (which i put in the Math object, but could go anywhere) which rounds “n” number to “d” decimal.
Math.roundTo = function(n,d){
return Math.round(n/d) * d;
}
so if num = 1294.2258
Math.roundTo(num,.1) would return 1294.2
Math.roundTo(num,10) returns 1290
and so on
thank you so much! that was the perfect solution!
:: Copyright KIRUPA 2024 //--