Skip to content

Number

Represents a double-precision floating point value. Supports exponents (XeY) and hexadecimal (0xAAAAAAAA) values. NaN is used to denote a invalid number. Infinity, negative infinity and NaN can be created using native number helpers.

Syntax (RegExp)
-?\d+(\.\d+)?
-?\d+(\.\d+)?e(\+|-)?\d+
-?0[Xx][A-Fa-f]+
Example
0
-140
-9.2
100
250.67
10e2
10e-4
0xfff

Properties

sign

Returns the -1 (less than zero), 0 (zero) or 1 (greater than zero).

Signature
-> : Number
Example
num := -5;

# prints -1
print(num.sign());

isFinite

Is the number finite?

Signature
-> : Boolean
Example
num := 5;

# prints true
print(num.isFinite());

isInfinite

Is the number infinite?

Signature
-> : Boolean
Example
num := 5;

# prints false
print(num.isInfinite());

isNaN

Is the number NaN?

Signature
-> : Boolean
Example
num := 5;

# prints false
print(num.isNaN());

isNegative

Is the number negative?

Signature
-> : Boolean
Example
num := 5;

# prints false
print(num.isNegative());

abs

Returns the number without sign.

Signature
-> : Number
Example
num := -5;

# prints 5
print(num.abs());

ceil

Returns the number rounded towards positive infinity.

Signature
-> : Number
Example
num := 5.1;

# prints 6
print(num.ceil());

round

Returns the number rounded towards negative infinity.

Signature
-> : Number
Example
num := 5.5;

# prints 6
print(num.round());

truncate

Returns the number discarding fractional digits.

Signature
-> : Number
Example
num := 5.45;

# prints 5
print(num.truncate());

toPrecisionString

Returns the number string with specified precision. Precision must satisfy 1 <= precision <= 21.

Signature
-> Number digits : String
Example
num := 5.2512;

# prints "5.25"
print(num.toPrecisionString(3));

toRadixString

Returns the radix equivalent of the number.

Signature
-> Number radix : String
Example
num := 5;

# prints 101
print(num.toRadixString(2));