Chapter 3 DynaScript Predefined Objects


Number object

Object

Enables you to use methods and obtain properties on a number.

Standard: ECMAScript

Syntax

To use a Number property:

Number.propertyName

To use a Number method:

Number.MethodName( parameter ) 

Description

The Number object represents a number for which you want to use methods and properties made available with the Number object. These methods and properties are not available to numbers that are held by variables ( num = 14 ).

You can call a Number object as a function:

Number( value ); 

or as a constructor:

myNumber = new Number( value );

When called as a function, a type conversion is performed and a number is returned. A new Number object is not created. When a Number object is created through a constructor, a Number object is returned.

The Number object has both a built-in object as well as constructors that allow users to create instances of a Number object. When referring to Number in the syntax sections of this chapter, we are referring to an instance of a Number object, not the built-in Number object.

Example

This example creates a Number object with the value of 32:

<!--SCRIPT 
    num = new Number( 32 );
    document.WriteLn( num );
-->

MAX_VALUE property

Syntax

Number.MAX_VALUE 

Attributes

This property is read-only.

Description

Returns the largest positive finite value of the number type, which is approximately 1.7976931348623157e308.

Return

Integer

Example

This example displays the largest possible number that can be used in PowerDynamo:

<!--SCRIPT
    document.WriteLn( Number.MAX_VALUE );
-->

MIN_VALUE property

Syntax

Number.MIN_VALUE 

Attributes

This property is read-only.

Description

Returns the smallest positive nonzero value of the number type, which is approximately 5e-324.

Return

Integer

Example

This example displays the smallest positive nonzero number that can be used in PowerDynamo:

<!--SCRIPT
    document.WriteLn( Number.MIN_VALUE );
-->

NaN property

Syntax

Number.NaN 

Attributes

This property is read-only.

Description

A value that indicates that an arithmetic expression returned a value that was not a number.

Return

String (NaN)

Example

This example has an output of NaN.

<!--SCRIPT
    document.WriteLn( Number.NaN );
-->

NEGATIVE_INFINITY property

Syntax

Number.NEGATIVE_INFINITY 

Attributes

This property is read-only.

Description

Returns a string indicating that a number is outside the range that ECMAScript is capable of representing.

Return

String (-Infinity)

Example

This example has an output of -Infinity :

<!--SCRIPT
    document.WriteLn( Number.NEGATIVE_INFINITY );
-->

POSITIVE_INFINITY property

Syntax

Number.POSITIVE_INFINITY 

Attributes

This property is read-only.

Description

Returns a string indicating that a number is outside the range that ECMAScript is capable of representing.

Return

String (Infinity)

Example

This example has an output of Infinity :

<!--SCRIPT
    document.WriteLn( Number.POSITIVE_INFINITY );
-->

toString method

Syntax

Number.toString( [radix] )

Description

Returns a string representation of the Number object. You can use a radix if you want to work with something other than base 10.

Return

String

Example

This example creates a number object and converts the value to a string:

<!--SCRIPT 
   num = new Number( 16 );
   stringNum = num.toString();
   document.WriteLn( stringNum );
-->

valueOf method

Syntax

Number.valueOf( )

Description

Extracts the number value of the number object as an integer.

Return

Integer

Example

This example creates a number object, and then converts it back to an integer, which is held in the variable intNum .

<!--SCRIPT 
   num = new Number( 16 );
   intNum = num.valueOf();
   document.WriteLn( intNum );
-->

 


Copyright © 2001 Sybase, Inc. All rights reserved.