Table of Contents
Numbers
Here is the documentation for Number.js.
Number.toInt, .toFloat
Number.toInt() just returns the number; useful because toInt must work on both Strings and Numbers. Note that if you call .toInt() on a float, you'll get an integer back.
var x = 10; x.toInt(); //returns 10

var x = 10.01; x.toFloat(); //returns 10.01

var x = 10.01; x.toInt(); //returns 10

Number.limit
(12).limit(2, 6.5) // returns 6.5

(-4).limit(2, 6.5) // returns 2

(4.3).limit(2, 6.5) // returns 4.3

Number.round
Returns the number rounded to specified precision: the number of digits after the decimal point. Can also be negative or zero (default).
12.45.round() // returns 12

12.45.round(1) // returns 12.5

12.45.round(-1) // returns 10

Number.times
Executes a passed in function the specified number of times:
(3).times(alert) //alert(0) //alert(1) //alert(2)

mootorial/03-native/02-number.txt · Last modified: 2011/01/14 03:48 by ralph