Skip to content

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) gives 15
  • 5 + 10 gives 15

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 -5
  • 5 - 10 gives -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) gives 50
  • 5 * 10 gives 50

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) gives 0.5
  • 5 / 10 gives 0.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) gives 5
  • 5 % 10 gives 5

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) gives 9765625
  • 5 ^ 10 gives 9765625

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) gives 1
  • min([1, 2, 3]) gives 1

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) gives 3
  • max([1, 2, 3]) gives 3

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) gives 6
  • sum([1, 2, 3], 4, 5) gives 15

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) gives 2
  • median([1, 2, 3], 4) gives 2.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) gives 2
  • mean([1, 2, 3], 4, 5) gives 3

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) gives 10
  • abs(-10) gives 10

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) gives 0
  • round(-0.6) gives -1
  • round(1.234, 0) gives 1
  • round(1.234, 2) gives 1.23
  • round(1234, -2) gives 1200

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) gives 1
  • ceil(-0.6) gives 0

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) gives 0
  • floor(-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) gives 2
  • sqrt(7) gives 2.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) gives 2.0800838230519041145
  • cbrt(64) gives 4

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) gives 2.7182818284590452354
  • exp(-1) gives 0.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) gives 0.99999999999999991342
  • ln(10) gives 2.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) gives 1
  • log10(100000) gives 5

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) gives 2
  • log2(1024) gives 10

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 -1
  • sign(10) gives 1

pi

Returns the ratio of a circle's circumference to its diameter.

pi() → number
  • pi() gives 3.1415926535897932385

e

Returns the base of the natural logarithm.

e() → number
  • e() gives 2.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") gives 2
  • toNumber(now()) gives 1693418100000
  • toNumber(true) gives 1

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"