External: Number

Number

The built in Number Object
Source:
number.js, line 7
See:

Methods

clamp(low, high) → {number}

add a clamp fn to the Number object
Parameters:
Name Type Description
low number lower limit
high number higher limit
Source:
number.js, line 23
Returns:
clamped value
Type
number

degToRad(angle) → {number}

Converts an angle in degrees to an angle in radians
Parameters:
Name Type Argument Default Description
angle number <optional>
"angle" angle in degrees
Source:
number.js, line 139
Returns:
corresponding angle in radians
Type
number
Example
// convert a specific angle
Number.prototype.degToRad (60); // return 1.0471...
// convert object value
var num = 60
num.degToRad(); // return 1.0471...

radToDeg(angle) → {number}

Converts an angle in radians to an angle in degrees.
Parameters:
Name Type Argument Default Description
angle number <optional>
"angle" angle in radians
Source:
number.js, line 156
Returns:
corresponding angle in degrees
Type
number
Example
// convert a specific angle
Number.prototype.radToDeg (1.0471975511965976); // return 59.9999...
// convert object value
num = 1.0471975511965976
Math.ceil(num.radToDeg()); // return 60

random(min, max) → {number}

return a random integer between min (included) and max (excluded)
Parameters:
Name Type Argument Default Description
min number <optional>
this minimum value.
max number maximum value.
Source:
number.js, line 41
Returns:
random value
Type
number
Example
// Print a random number; one of 5, 6, 7, 8, 9
console.log( (5).random(10) );
// Select a random array element
var ar = [ "foo", "bar", "baz" ];
console.log(ar[ (0).random(ar.length) ]);

randomFloat(min, max) → {number}

return a random float between min, max (exclusive)
Parameters:
Name Type Argument Default Description
min number <optional>
this minimum value.
max number maximum value.
Source:
number.js, line 63
Returns:
random value
Type
number
Example
// Print a random number; one of 5, 6, 7, 8, 9
console.log( (5).random(10) );
// Select a random array element
var ar = [ "foo", "bar", "baz" ];
console.log(ar[ (0).random(ar.length) ]);

round(num, dec) → {number}

round a value to the specified number of digit
Parameters:
Name Type Argument Default Description
num number <optional>
this value to be rounded.
dec number number of decimal digit to be rounded to.
Source:
number.js, line 108
Returns:
rounded value
Type
number
Example
// round a specific value to 2 digits
Number.prototype.round (10.33333, 2); // return 10.33
// round a float value to 4 digits
num = 10.3333333
num.round(4); // return 10.3333

toHex() → {string}

a quick toHex function
given number must be an int, with a value between 0 and 255
Source:
number.js, line 122
Returns:
converted hexadecimal value
Type
string

weightedRandom(min, max) → {number}

return a weighted random between min, max (exclusive) favoring the lower numbers
Parameters:
Name Type Argument Default Description
min number <optional>
this minimum value.
max number maximum value.
Source:
number.js, line 86
Returns:
random value
Type
number
Example
// Print a random number; one of 5, 6, 7, 8, 9
console.log( (5).random(10) );
// Select a random array element
var ar = [ "foo", "bar", "baz" ];
console.log(ar[ (0).random(ar.length) ]);
Copyright © 2011 - 2017, Olivier Biot, Jason Oster, Aaron McLeod
Documentation generated by JSDoc 3.4.0 on 2017-02-28T11:37:40+08:00 using the DocStrap template modified by codename-.