Predefined functions for number

toString

Returns a string representing a number. radix parameter defines the radix of numeral system which will be used to represent number.

If radix is omitted than the number will be represented in decimal numeral system.

Parameters

NameTypeDescription
radixnumber?An integer in the range 2 through 36 specifying the base to use for representing numeric values.

Returns

A string representing a number

Examples

node some_node { do { var num: number = 15; #log(num.toString()); // "15" #log(num.toString(10)); // "15" #log(num.toString(2)); // "1111" #log(num.toString(15)); // "10" } }

toPrecision

Returns a string containing a number represented either in exponential or fixed-point notation with a specified number of digits.

Parameters

NameTypeDescription
precisionnumber?An integer specifying the number of significant digits.

Returns

string - a string representing a Number object in fixed-point or exponential notation rounded to precision significant digits.

Examples

node some_node { do { var num = 15.56789; #log(num.toPrecision()); // 15.56789 #log(num.toPrecision(3)); // 15.6 #log((1e-4).toPrecision()); // 0.0001 #log((1e-4).toPrecision(1)); // 0.0001 #log((1e-4).toPrecision(7)); // 0.0001000000 } }

toFixed

Returns a string representing a number in fixed-point notation.

If fractionDigits is omitted, it is treated as 0.

Note:

  • if the fractionDigits > 20 than behaviour of toFixed is undefined.

Parameters

NameTypeDescription
fractionDigitsnumber?The number of digits to appear after the decimal point; this may be a value in range [0,20]

Returns

string - a string representing the given number using fixed-point notation.

Examples

node some_node { do { var num = 15.56789; #log(num.toFixed()); // "16" #log(num.toFixed(3)); // "15.568" #log((1e-4).toFixed()); // "0" #log((1e-4).toFixed(1)); // "0.0" #log((1e-4).toFixed(7)); // "0.0001000" } }

toExponential

Returns a string containing a number represented in exponential notation.

If the fractionDigits is omitted than as many digits as necessary to specify the number are used to represent it.

Parameters

NameTypeDescription
fractionDigitsnumber?An integer specifying the number of digits after the decimal point.

Returns

string - a string representing the given number in exponential notation with one digit before the decimal point, rounded to fractionDigits digits after the decimal point.

Examples

node some_node { do { var num = 15.56789; #log(num.toExponential()); // "1.556789e+1" #log(num.toExponential(3)); // "1.557e+1" set num = 1e-4; #log(num.toExponential()); // "1e-4" #log(num.toExponential(1)); // "1.0e-4" #log(num.toExponential(7)); // "1.0000000e-4" } }

isNaN

Returns true if the value of a number is NaN (reserved value representing Not-A-Number), false otherwise.

Parameters

None

Returns

true if the value of a number is NaN (reserved value representing Not-A-Number), false otherwise.

Examples

node some_node { do { #log("ss".parseNumber().isNaN()); // true #log((1e-4).isNaN()); // false #log((10).isNaN()); // false } }

isInteger

Returns true if the value of a number is an integer, false otherwise.

Parameters

None

Returns

true if the value of a number is an integer, false otherwise.

Examples

node some_node { do { #log("ss".parseNumber().isInteger()); // false #log((1e-4).isInteger()); // false #log((3.1415).isInteger()); // false #log((10).isInteger()); // true } }

isFinite

Returns true if the value of a number is finite, false otherwise.

Parameters

None

Returns

true if the value of a number is finite, false otherwise.

Examples

node some_node { do { #log((10/0).isFinite()); // false #log("ss".parseNumber().isFinite()); // false #log((10).isFinite()); // true #log((10e+100).isFinite()); // true #log((10e+1000).isFinite()); // false } }

ceil

Returns the smallest integer greater than or equal to the value of a number.

Parameters

None

Returns

number - the smallest integer greater than or equal to the value of a number

Examples

node some_node { do { #log((10.289).ceil()); // 11 #log((10.9).ceil()); // 11 #log((10).ceil()); // 10 } }

floor

Returns the greatest integer less than or equal to the value of a number.

Parameters

None

Returns

number - the greatest integer less than or equal to the value of a number.

Examples

node some_node { do { #log((10.289).floor()); // 10 #log((10.9).floor()); // 10 #log((10).floor()); // 10 } }

round

Returns the value of a number rounded to the nearest integer.

Parameters

None

Returns

number - the value of a number rounded to the nearest integer.

Examples

node some_node { do { #log((10.289).round()); // 10 #log((10.9).round()); // 11 #log((10).round()); // 10 } }

trunc

Returns the integer part of a number by removing any fractional digits.

Parameters

None

Returns

number - the integer part of a number by removing any fractional digits.

Examples

node some_node { do { #log((10.289).trunc()); // 10 #log((10.9).trunc()); // 10 #log((10).trunc()); // 10 } }
Found a mistake? Let us know.

Enroll in beta

Request invite to our private Beta program for developers to join the waitlist. No spam, we promise.