Number

Moduleejs
Definitionfinal class Number
InheritanceNumber inherit Object
StabilityEvolving.

The Number type is used by all numeric values in Ejscript.

Depending on how Ejscript is configured, the underlying number representation may be based on either an int, long, int64 or double data type. If the underlying type is integral (not double) then some of these routines may not be relevant.


Properties

QualifiersPropertyTypeDescription
public static const MAX_VALUENumberReturn the maximim value this number type can assume. Alias for MaxValue. An object of the appropriate number with its value set to the maximum value allowed.
public static const MaxValueNumberReturn the maximim value this number type can assume.
public static const MIN_VALUENumberReturn the minimum value this number type can assume. Alias for MinValue. An object of the appropriate number with its value set to the minimum value allowed.
public static const MinValueNumberReturn the minimum value this number type can assume.
public static const NaNNumberNot a Number. This is the result of an arithmetic expression which has no value.
public static const NEGATIVE_INFINITYNumberReturn a unique value which is less than or equal then any value which the number can assume.
public static const POSITIVE_INFINITYNumberReturn a unique value which is greater then any value which the number can assume.
public get absNumberThe absolute value of a number (which is equal to its magnitude).
public get byteNumberByte sized integral number. Numbers are rounded and truncated as necessary.
public get ceilNumberThe smallest integral number that is greater or equal to the number value.
public get floorNumberThe largest integral number that is smaller than the number value.
public get isFiniteBooleanIs the number Infinity or -Infinity. Set to true or false.
public get isNaNBooleanIs the number is equal to the NaN value. If the numeric type is integral, this will always return false.
public get roundNumberCompute the integral number that is closest to this number. Ie. round up or down to the closest integer.

Number Methods

QualifiersMethod
iterator override get(): Iterator
 Return an iterator that can be used to iterate a given number of times.
iterator override getValues(): Iterator
 Return an iterator that can be used to iterate a given number of times.
public integral(size: Number = 32): Number
 Convert this number to an integral value of the specified number of bits.
public max(other: Array): Number
 Returns the greater of the number and the arguments.
public min(other: Array): Number
 Returns the lessor of the number and the arguments.
Number(value: Object = null)
 Number constructor.
public power(nth: Number): Number
 Returns a number which is equal to this number raised to the power of the argument.
public toExponential(fractionDigits: Number = 0): String
 Returns the number formatted as a string in scientific notation with one digit before the decimal point and the argument number of digits after it.
public toFixed(fractionDigits: Number = 0): String
 Returns the number formatted as a string with the specified number of digits after the decimal point.
public toPrecision(numDigits: Number = MAX_VALUE): String
 Returns the number formatted as a string in either fixed or exponential notation with argument number of digits.
public override toString(radix: Number = 10): String
 This function converts the number to a string representation.

Method Detail

override iterator get(): Iterator

Return an iterator that can be used to iterate a given number of times.

Description
This is used in for/in statements.
Returns
An iterator.
Specified
ejscript-1.1
Example
for (i in 5) 
    print(i)

override iterator getValues(): Iterator

Return an iterator that can be used to iterate a given number of times.

Description
This is used in for/each statements.
Returns
An iterator.
Specified
ejscript-1.1
Example
for each (i in 5) 
    print(i)

public integral(size: Number = 32): Number

Convert this number to an integral value of the specified number of bits.

Description
Floating point numbers are converted to integral values using truncation.
Parameters
size: Number [default: 32]
Returns
An integral number.
Specified
ejscript-1.1

public max(other: Array): Number

Returns the greater of the number and the arguments.

Parameters
other: Array Other numbers number to compare with.
Returns
A number.
Specified
ejscript-1.1

public min(other: Array): Number

Returns the lessor of the number and the arguments.

Parameters
other: Array Numbers to compare with.
Returns
A number.
Specified
ejscript-1.1

public Number(value: Object = null)

Number constructor.

Parameters
value: Object Value to use in creating the Number object. If the value cannot be converted to a number, the value will ba NaN (or 0 if using integer numerics). [default: null]

public power(nth: Number): Number

Returns a number which is equal to this number raised to the power of the argument.

Parameters
nth: Number Nth power to be raised to.
Returns
A number.
Specified
ejscript-1.1

public toExponential(fractionDigits: Number = 0): String

Returns the number formatted as a string in scientific notation with one digit before the decimal point and the argument number of digits after it.

Parameters
fractionDigits: Number The number of digits in the fraction. [default: 0]
Returns
A string representing the number.

public toFixed(fractionDigits: Number = 0): String

Returns the number formatted as a string with the specified number of digits after the decimal point.

Parameters
fractionDigits: Number The number of digits in the fraction. [default: 0]
Returns
A string representing the number.

public toPrecision(numDigits: Number = MAX_VALUE): String

Returns the number formatted as a string in either fixed or exponential notation with argument number of digits.

Parameters
numDigits: Number The number of digits in the result. If omitted, the entire number is returned. [default: MAX_VALUE]
Returns
A string.

override public toString(radix: Number = 10): String

This function converts the number to a string representation.

Parameters
radix: Number Radix to use for the conversion. Defaults to 10. Non-default radixes are currently not supported. [default: 10]
Returns
A string representation of the number.