A collection of the Number Object methods.
Every Math method is mirrored in the Number object, both as prototype and generic.
Limits this number between two bounds.
myNumber.limit(min, max);
(12).limit(2, 6.5); //Returns: 6.5 (-4).limit(2, 6.5); //Returns: 2 (4.3).limit(2, 6.5); //Returns: 4.3
Returns this number rounded to the specified precision.
myNumber.round([precision]);
(12.45).round() //Returns: 12 (12.45).round(1) //Returns: 12.5 (12.45).round(-1) //Returns: 10
Executes the function passed in the specified number of times.
myNumber.times(fn[, bind]);
(4).times(alert); //Alerts "0", then "1", then "2", then "3".
Returns this number as a float. Useful because toFloat must work on both Strings and Numbers.
myNumber.toFloat();
(111).toFloat(); //returns 111 (111.1).toFloat(); //returns 111.1
Returns this number as another number with the passed in base. Useful because toInt must work on both Strings and Numbers.
myNumber.toInt([base]);
(111).toInt(); //returns 111 (111.1).toInt(); //returns 111 (111).toInt(2); //returns 7
This documentation is released under a Attribution-NonCommercial-ShareAlike 3.0 License.