The Number Object


The Number Object

As you can guess from its name , the Number object handles numbers. Mostly, there's little need to use this object, because you can just use simple numbers instead, and JavaScript is good at that. In fact, JavaScript creates Number objects from simple numbers automatically as it needs them. It's useful to know the properties and methods of the Number object, however, and you can find them in Table 19.4 in overview, its properties in depth in Table 19.5, and its methods in depth in Table 19.6.

Table 19.4. Overview of the Properties and Methods of the Number Object

Properties

Methods

constructor

toExponential

MAX_VALUE

toFixed

MIN_VALUE

toLocaleString

NaN

toPrecision

NEGATIVE_INFINITY

toString

POSITIVE_INFINITY

valueOf

Prototype

 
Table 19.5. The Properties of the Number Object

Property

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

constructor

   

x

x

   

x

x

x

x

 

Read/write

 

This property specifies the function that creates an object.

MAX_VALUE

 

x

x

x

 

x

x

x

x

x

 

Read-only

 

This property holds the maximum possible numeric value JavaScript can handle, typically about 1.79E+308.

MIN_VALUE

 

x

x

x

 

x

x

x

x

x

 

Read-only

 

This property holds the minimum possible numeric value JavaScript can handle, typically about 5.00E-324.

NaN

 

x

x

x

 

x

x

x

x

x

 

Read-only

 

This property, "Not a Number," is a special value that indicates an arithmetic expression returned a value that was not a number.

NEGATIVE_INFINITY

   

x

x

x

 

x

x

x

x

x

                   
 

Read-only

 

This property is how JavaScript refers to negative infinity.

POSITIVE_INFINITY

   

x

x

x

 

x

x

x

x

x

                   
 

Read-only

 

This property is how JavaScript refers to positive infinity.

prototype

   

x

x

   

x

x

x

x

 

Read/write

 

This property returns a reference to the object's prototype. You use the prototype property to provide base functionality to a class of objects. See "Using the prototype Property" in this chapter.

Table 19.6. The Methods of the Number Object

Method

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

toExponential

     

x

       

x

x

 

Returns: String

 

This method returns a string containing a number in exponential form.

 

Syntax: number .toExponential( digits ) , where digits is the number of digits after the decimal point.

toFixed

     

x

       

x

x

 

Returns: String

 

This method returns a string containing the number in fixed-point notation.

 

Syntax: number .toFixed( digits ) , where digits is the number of digits after the decimal point.

toLocaleString

     

x

       

x

x

 

Returns: String

 

This method returns a number converted to a string using the current locale.

 

Syntax: number .toLocaleString() .

toPrecision

     

x

       

x

x

 

Returns: String

 

This method returns a string containing a number in either exponential or fixed-point form with a specified number of digits.

 

Syntax: number .toPrecision( digits ) , where digits is the number of significant (total) digits.

toString

 

x

x

x

   

x

x

x

x

 

Returns: String

 

This method returns the number as a string.

 

Syntax: number .toString() .

valueOf

   

x

x

   

x

x

x

x

 

Returns: Number

 

This method returns the value of the number contained by the Number object.

 

Syntax: number .valueOf() .



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net