Skip to main content

Number type

Numbers are used for all kinds of calculations. There are literal numbers, like 7 or 1.5, but a component or variable can also be of type number. Both kinds can be used interchangeably and everything described on this page applies to either kind. For example, you can call a function like round() on a component: price.round() or on a literal number: 13.5.round().

Operations

nameexampleresultdescription
negate-price-5gets the inverse of a number
addprice + 27adds two numbers
subtract2 - price-3subtracts one number from another
multiply2 * price10multiplies two numbers
divide2 / price2.5divides one number by another
exponentiationprice ^ 225raises a number to the power of another number
moduloprice mod 21divides one number by another and returns the remainder

Comparing numbers

In addition to the above, there are also six operators for comparing numbers.

nameexampleresultdescription
greater thanprice > 5falsereturns true if the first number is greater than the second
greater than or equalprice >= 5truereturns true if the first number is greater than or equal to the second
less than4 < pricetruereturns true if the first number is less than the second
less than or equal4 <= pricefalsereturns true if the first number is less than or equal to the second
equal toprice = 5truereturns true if one number is equal to another
not equal toprice <> 19truereturns true if one number is not equal to another

Functions

namedescription
round(digits)rounds a number to the nearest integer or to the specified number of fractional digits
floorgets the largest integer less than or equal to the specified number
ceilinggets the smallest integer greater than or equal to the specified number
truncatecalculates the integral part of a number
atLeast(min)gets a number that is greater than or equal to the specified threshold
atMost(max)gets a number that is less than than or equal to the specified threshold
toText(format,locale)converts a number to text
info

For additional mathematical functions check out the article about the math type.

round

Rounds a number to the specified number of fractional digits, away from zero.
If no parameter is used, or the number of digits is zero, rounds to the nearest integer.

exampleresult
price.round()4
price.round(1)4.4
price.round(2)4.45
info

If you specify a negative number of digits, its positive inverse will be used, i.e. round(-2) is the same as round(2).


floor

Returns the largest integer that is less than or equal to the specified number.

exampleresult
1.1.floor()1
1.9.floor()1
(-1.1).floor()-2

ceiling

Returns the smallest integer that is greater than or equal to the specified number.

exampleresult
1.1.ceiling()2
1.3.ceiling()2
(-1.1).ceiling()-1

truncate

Calculates the integral part of a number by rounding it to the nearest integer towards zero.

exampleresult
1.1.truncate()1
1.9.truncate()1
(-1.9).truncate()-1

atLeast(min)

Compares a number to a specified threshold and returns it if it is greater than or equal to the threshold, otherwise returns the threshold.

exampleresult
5.atLeast(10)10
5.atLeast(3)5

atMost(max)

Compares a number to a specified threshold and returns it if it is less than or equal to the threshold, otherwise returns the threshold.

exampleresult
5.atMost(2)2
5.atMost(10)5

toText(format,locale)

Converts a number to text. You can optionally customize the conversion with the format parameter and specify the desired locale.

exampleresult
price.toText()"4.445"
price.toText("€ 0.##")"€ 4.45"
1337.toText("$ 0,0.00")"$ 1,337.00"
1337.toText("€ 0,0.00", Locale.de)"€ 1.337,00"

You may use a combination of the following characters to customize the conversion of numbers to text.

zero placeholder (O)

Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result text.
123.456.toText("0000") becomes 0123
123.toText("000.00") becomes 123.00

digit placeholder (#)

Replaces the hash sign with the corresponding digit if one is present; otherwise, no digit appears in the result text.
123.456.toText("####") becomes 123
123.toText("###.##") becomes 123

decimal placeholder (.)

Determines the location of the decimal separator in the result text.
0.1234.toText("0.00") becomes 0.12

group separator placeholder (,)

Inserts a localized group separator between each number group in the integral part of the output.
12345678.toText("##,#") becomes 12,345,678

percentage placeholder (%)

Multiplies a number by 100 and inserts a percentage symbol in the result text.
0.35.toText("0%") becomes 35%

section separator (;)

Defines sections with separate format strings for positive, negative and zero numbers.
(-13.37).toText("##.##;(##.##)") becomes (13.37)

Other characters

All characters that have not been mentioned above will simply be copied to the result text:
24.toText("0 degrees") becomes 24 degrees

In order to use placeholder characters literally, you can precede them with a backslash:
13.37.toText("\# 00.0") becomes # 13.4

You can also use single quotes ' or double quotes " to enclose literal text that should be copied to the result:
13.37.toText("00.0'% of total'") becomes 13.4% of total

Rounding

If the formatted value contains more significant digits than are present in the format text, the value will be rounded to the nearest digit and away from zero.
10.5.toText("#") becomes 11
0.25.toText("0.0") becomes 0.3