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
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
var x = 10.01; x.toFloat(); //returns 10.01
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
var x = 10.01; x.toInt(); //returns 10
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
Number.limit
(12).limit(2, 6.5) // returns 6.5
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
(-4).limit(2, 6.5) // returns 2
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
(4.3).limit(2, 6.5) // returns 4.3
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
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
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
12.45.round(1) // returns 12.5
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
12.45.round(-1) // returns 10
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
Number.times
Executes a passed in function the specified number of times:
(3).times(alert) //alert(0) //alert(1) //alert(2)
![Execute This Code::Clicking this will run this code; check your console for the result. execute this code](../../../../css/art/execute.gif)
mootorial/03-native/02-number.txt · Last modified: 2011/01/14 03:48 by ralph