SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Fix() Method
By Scott Isaacs

This adds a fix method to the JavaScript number object. The fix() method returns the number rounded to the specified number of digits.

For example,

Number.fix() Method Code

function _fix(dig) {
 // dig specifies how many digits
 // Invalid values default to 0.
 if ((dig<0) || (dig==null) || (isNaN(dig))) dig=0
 var power = Math.pow(10,dig)
 return Math.round(this.valueOf()*power)/power;
}
Number.prototype.fix = _fix      
Discuss and Rate this Article