JS Number Object
CSGNetwork FREE Source Code, Javascript Source, and Code Snippets!
CSGNetwork Custom Search
     Bookmark and Share
 
CSGNetwork
Snippets
Calculators
Top Free Apps
Home
Back



Right click this window and select "view source" in order to copy the source for this script.

Number Object

The Number object is an object wrapper for primitive numeric values. It contains some useful methods, introduced in JavaScript 1.5.

Constructor:

new Number(value)
Number (value)

where "value" is the numeric value of the Number object to be created, or value to be converted to a number.

Properties

Properties Description
MAX_VALUE The largest representable number in JavaScript.
MIN_VALUE The smallest representable number in JavaScript.
NaN "Not a number" value.
NEGATIVE_INFINITY Negative infinity, returned on overflow.
POSITIVE_INFINITY Infinity, returned on overflow.
prototype Prototype property, to add custom properties and methods to this object.

Methods

Methods Description
toExponential(x) Returns a number in exponential notation (string format). "x" should be a number between 0 and 20, dictating the number of digits to include in the notation after the decimal place.
toFixed(x) Formats any number for "x" number of trailing decimals. The number is rounded up, and "0"s are used after the decimal point if needed to create the desired decimal length. Example(s)
toPrecision(x) Formats any number so it is of "x" length. Also called significant digits. A decimal point and "0"s are used if needed to create the desired length.

Note: All methods above are introduced in JavaScript 1.5, and only supported in IE6+ and NS6+.

Examples

toFixed(x)

var profits=2489.8237
profits.toFixed(3) //returns 2489.824 (round up)
profits.toFixed(2) //returns 2489.82



Bookmark and Share
Registered® Trademark™ and Copyright© 1973 - CSG, Computer Support Group, Inc. and CSGNetwork.Com All Rights Reserved