#830 enhancement
Radoslav Stankov

Add percision to Number#round

Reported by Radoslav Stankov | October 18th, 2009 @ 09:34 PM

I think it will be very good to have precision argument.


(100/45).round();   // -> 2
(100/45).round(1);  // -> 2.2
(100/45).round(2);  // -> 2.22
(100/45).round(3);  // -> 2.222
(100/45).round(4);  // -> 2.2222
(100/45);           // -> 2.2222222222222223

possible code could be:

Number.prototype.round = function(precision){
    if (Object.isUndefined(precision)){
        return Math.round(this);
    return parseFloat(this.toFixed(precision));

If such addition to Prototype is accepted, I'll make a patch for this with all unit-test with it

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket