Number
Module | ejs |
Definition | final class Number |
Inheritance | Number ![]() |
Stability | Evolving. |
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
Qualifiers | Property | Type | Description |
---|---|---|---|
public static const | MAX_VALUE | Number | Return 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 | MaxValue | Number | Return the maximim value this number type can assume. |
public static const | MIN_VALUE | Number | Return 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 | MinValue | Number | Return the minimum value this number type can assume. |
public static const | NaN | Number | Not a Number. This is the result of an arithmetic expression which has no value. |
public static const | NEGATIVE_INFINITY | Number | Return a unique value which is less than or equal then any value which the number can assume. |
public static const | POSITIVE_INFINITY | Number | Return a unique value which is greater then any value which the number can assume. |
public get | abs | Number | The absolute value of a number (which is equal to its magnitude). |
public get | byte | Number | Byte sized integral number. Numbers are rounded and truncated as necessary. |
public get | ceil | Number | The smallest integral number that is greater or equal to the number value. |
public get | floor | Number | The largest integral number that is smaller than the number value. |
public get | isFinite | Boolean | Is the number Infinity or -Infinity. Set to true or false. |
public get | isNaN | Boolean | Is the number is equal to the NaN value. If the numeric type is integral, this will always return false. |
public get | round | Number | Compute the integral number that is closest to this number. Ie. round up or down to the closest integer. |
Number Methods
Qualifiers | Method |
---|---|
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
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)
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)
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
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
Returns the lessor of the number and the arguments.
- Parameters
other: Array Numbers to compare with.
- Returns
- A number.
- Specified
- ejscript-1.1
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]
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
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.
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.
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.
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.