Number functions
Every function in this family, with its signature and examples. Each example runs as a test of the language. See Language basics for how calls, types, and operators work.
add
Returns the sum of two numbers.
add(a: number, b: number) → number
Also callable as receiver.add(…), with the receiver as the first argument.
add(5, 10)gives155 + 10gives15
subtract
Returns the difference of two numbers.
subtract(a: number, b: number) → number
Also callable as receiver.subtract(…), with the receiver as the first argument.
subtract(5, 10)gives-55 - 10gives-5
multiply
Returns the product of two numbers.
multiply(a: number, b: number) → number
Also callable as receiver.multiply(…), with the receiver as the first argument.
multiply(5, 10)gives505 * 10gives50
divide
Returns the quotient of two numbers.
divide(a: number, b: number) → number
Also callable as receiver.divide(…), with the receiver as the first argument.
divide(5, 10)gives0.55 / 10gives0.5
mod
Returns the first number modulo the second number; the result has the sign of the first.
mod(a: number, b: number) → number
Also callable as receiver.mod(…), with the receiver as the first argument.
mod(5, 10)gives55 % 10gives5
pow
Returns the result of a base number raised to an exponent power.
pow(a: number, b: number) → number
Also callable as receiver.pow(…), with the receiver as the first argument.
pow(5, 10)gives97656255 ^ 10gives9765625
min
Returns the smallest number of the arguments.
min(a: number, b: number, …more: number) → number
min(list: list<number>, …more: number) → number
Also callable as receiver.min(…), with the receiver as the first argument.
min(1, 2, 3)gives1min([1, 2, 3])gives1
max
Returns the largest number of the arguments.
max(a: number, b: number, …more: number) → number
max(list: list<number>, …more: number) → number
Also callable as receiver.max(…), with the receiver as the first argument.
max(1, 2, 3)gives3max([1, 2, 3])gives3
sum
Returns the sum of its arguments.
sum(a: number, b: number, …more: number) → number
sum(list: list<number>, …more: number) → number
Also callable as receiver.sum(…), with the receiver as the first argument.
sum(1, 2, 3)gives6sum([1, 2, 3], 4, 5)gives15
median
Returns the middle value of its arguments.
median(a: number, b: number, …more: number) → number
median(list: list<number>, …more: number) → number
Also callable as receiver.median(…), with the receiver as the first argument.
median(1, 2, 4)gives2median([1, 2, 3], 4)gives2.5
mean
Returns the arithmetic average of its arguments.
mean(a: number, b: number, …more: number) → number
mean(list: list<number>, …more: number) → number
Also callable as receiver.mean(…), with the receiver as the first argument.
mean(1, 2, 3)gives2mean([1, 2, 3], 4, 5)gives3
abs
Returns the absolute value of the number.
abs(number: number) → number
Also callable as receiver.abs(…), with the receiver as the first argument.
abs(10)gives10abs(-10)gives10
round
Returns the number rounded to the nearest integer, or to the given decimal places; halves round away from zero.
round(number: number, places?: number) → number
Also callable as receiver.round(…), with the receiver as the first argument.
round(0.4)gives0round(-0.6)gives-1round(1.234, 0)gives1round(1.234, 2)gives1.23round(1234, -2)gives1200
ceil
Returns the smallest integer greater than or equal to the number.
ceil(number: number) → number
Also callable as receiver.ceil(…), with the receiver as the first argument.
ceil(0.4)gives1ceil(-0.6)gives0
floor
Returns the largest integer less than or equal to the number.
floor(number: number) → number
Also callable as receiver.floor(…), with the receiver as the first argument.
floor(0.4)gives0floor(-0.6)gives-1
sqrt
Returns the positive square root of the number.
sqrt(number: number) → number
Also callable as receiver.sqrt(…), with the receiver as the first argument.
sqrt(4)gives2sqrt(7)gives2.6457513110645905905
cbrt
Returns the cube root of the number.
cbrt(number: number) → number
Also callable as receiver.cbrt(…), with the receiver as the first argument.
cbrt(9)gives2.0800838230519041145cbrt(64)gives4
exp
Returns e^x, where x is the argument, and e is Euler's number (2.718…), the base of the natural logarithm.
exp(number: number) → number
Also callable as receiver.exp(…), with the receiver as the first argument.
exp(1)gives2.7182818284590452354exp(-1)gives0.3678794411714423216
ln
Returns the natural logarithm of the number.
ln(number: number) → number
Also callable as receiver.ln(…), with the receiver as the first argument.
ln(2.718281828459045)gives0.99999999999999991342ln(10)gives2.302585092994045684
log10
Returns the base 10 logarithm of the number.
log10(number: number) → number
Also callable as receiver.log10(…), with the receiver as the first argument.
log10(10)gives1log10(100000)gives5
log2
Returns the base 2 logarithm of the number.
log2(number: number) → number
Also callable as receiver.log2(…), with the receiver as the first argument.
log2(4)gives2log2(1024)gives10
sign
Returns 1 if the number is positive, -1 if it is negative, and 0 if it is zero.
sign(number: number) → number
Also callable as receiver.sign(…), with the receiver as the first argument.
sign(-10)gives-1sign(10)gives1
pi
Returns the ratio of a circle's circumference to its diameter.
pi() → number
pi()gives3.1415926535897932385
e
Returns the base of the natural logarithm.
e() → number
e()gives2.7182818284590452354
toNumber
Converts a value to a number; the number conversion for a function or operator that needs a number. Text is parsed, a boolean is 1 or 0 and a date is its Unix timestamp in milliseconds.
toNumber(value: text | number | boolean | date) → number
Also callable as receiver.toNumber(…), with the receiver as the first argument.
toNumber("2")gives2toNumber(now())gives1693418100000toNumber(true)gives1
formatNumber
Formats the number as text: "commas" (the default) groups thousands, "usd" writes dollars, "humanize" abbreviates to K, M, B or T. The optional third argument, which fixes the decimal places, is a Fontana extension: Notion 2.0 is formatNumber(number, format).
formatNumber(number: number, format?: text, places?: number) → text
Also callable as receiver.formatNumber(…), with the receiver as the first argument.
formatNumber(1234567.891)gives"1,234,567.891"formatNumber(1234567.891, "commas", 2)gives"1,234,567.89"formatNumber(1234567.891, "humanize")gives"1.2M"formatNumber(-1234.5, "usd")gives"-$1,234.50""Revenue: " + formatNumber(1234.5, "usd", 0)gives"Revenue: $1,235"