To make it more generic … I change the prototype of Number object in Javascript by doing this
Number.prototype.ceil = function() { return Math.ceil(this); };
Now 2.3.ceil() returns 3 and 2.ceil() throws exception.
But if I do b=2 and then do b.ceil() , it works fine!! So, basically it is still a problem of javascript.
The method is
Math.ceil, it’s not an instance method.It looks like it would be trivial to create a prototype method that can do this:
It also looks like JavaScript reserves the first decimal in numeric literals for adding decimals to the number. This is a language feature. To get around this, you need two decimals: