Edit: To answer your edit, use Math.round
. You could also prototype the Number
object to have it do your bidding if you prefer that syntax.
Number.prototype.round = function() {
return Math.round(this);
}
var num = 3.5;
alert(num.round())
I’ve never used Number.toFixed()
before (mostly because most JS libraries provide a toInt()
method), but judging by your results I would say it would be more consistent to use the Math
methods (round
, floor
, ceil
) then toFixed
if cross-browser consistency is what you are looking for.