Numeric functions
Numeric functions compute numbers: the absolute value and the rounding of a number (absolute, round,
round-down, round-up), and the total, smallest, largest and average value of a sequence of numbers (sum, min,
max, average).
Other functions also return a number. You find them with the values that they work on:
-
sequences: count, count-duplicates and index-of;
-
texts: string-length and index-of-substring;
-
dates, times and durations: year, hours, days and the other functions that take a part of a date, a time or a duration;
-
conversion: number.
You write arithmetic with operators (see Arithmetic operators).
If the argument of absolute, round, round-down or round-up has no value, the result has no value. If the
argument is NaN ("not a number", the result of a conversion that failed), the result is NaN.
absolute
Returns the absolute value of a number.
absolute(<number>) → number
- <number>
-
number. The number whose absolute value you want.
The result is the number without its sign: absolute(-5) and absolute(5) both give 5.
Examples
absolute(-5)
absolute(BT-00-Number - BT-12-Number) <= 10
Checks that two numbers differ by at most 10, in either direction.
| New in EFX-2. |
See also: Arithmetic operators
round
Rounds a number to the nearest whole number.
round(<number>) → number
- <number>
-
number. The number to round.
round rounds a number exactly halfway between two whole numbers up, towards positive infinity: 2.5 gives 3,
and -2.5 gives -2. You cannot give a number of decimal places. To round to two decimal places, multiply and
divide: round(<number> * 100) / 100.
Examples
round(2.5)
Gives 3.
round(BT-00-Number * 100) / 100
Rounds to two decimal places.
| New in EFX-2. |
See also: round-down, round-up, format-number
round-down
Rounds a number down to a whole number.
round-down(<number>) → number
- <number>
-
number. The number to round.
The result is the largest whole number that is not greater than <number>: 2.7 gives 2, and -2.5 gives -3.
Examples
round-down(2.7)
Gives 2.
round-down(BT-00-Number / 12)
The number of whole dozens in a number.
| New in EFX-2. |
round-up
Rounds a number up to a whole number.
round-up(<number>) → number
- <number>
-
number. The number to round.
The result is the smallest whole number that is not less than <number>: 2.1 gives 3, and -2.5 gives -2.
Examples
round-up(2.1)
Gives 3.
round-up(BT-00-Number / 12)
The number of dozens needed to hold a number of items.
| New in EFX-2. |
See also: round, round-down
sum
Returns the total of a sequence of numbers.
sum(<sequence>) → number
- <sequence>
-
sequence of numbers. The numbers to add.
The result is the sum of all the numbers in the sequence. If the sequence is empty, the result is 0. If one of the
numbers is NaN, the result is NaN.
Restrictions
-
The sequence must contain numbers. A sequence of another type is an error.
Examples
sum(BT-13-Number)
The total of the values of the repeatable field BT-13-Number.
sum(BT-13-Number) <= BT-00-Number
sum(for context:$n in ND-RepeatableNode return count($n::BT-00-Text-In-Repeatable-Node))
Adds up a number computed for each occurrence of a repeatable node.
min
Returns the smallest number of a sequence.
min(<sequence>) → number
- <sequence>
-
sequence of numbers. The numbers to compare.
If the sequence is empty, the result has no value. If one of the numbers is NaN, the result is NaN.
Restrictions
-
The sequence must contain numbers. To find the earliest date, sort the dates and take the first one:
sort(<dates>)[at 1](see sort).
Examples
min(BT-13-Number)
min(BT-13-Number) >= 0
Checks that no value of the repeatable field is negative.
| New in EFX-2. |
max
Returns the largest number of a sequence.
max(<sequence>) → number
- <sequence>
-
sequence of numbers. The numbers to compare.
If the sequence is empty, the result has no value. If one of the numbers is NaN, the result is NaN.
Restrictions
-
The sequence must contain numbers. To find the latest date, sort the dates and take the last one:
reverse(sort(<dates>))[at 1](see sort).
Examples
max(BT-13-Number)
max(BT-13-Number) <= BT-00-Number
Checks that no value of the repeatable field is greater than a maximum given in another field.
| New in EFX-2. |
average
Returns the arithmetic mean of a sequence of numbers.
average(<sequence>) → number
- <sequence>
-
sequence of numbers. The numbers to average.
The result is the sum of the numbers divided by the number of values. If the sequence is empty, the result has no value. If one of the numbers is NaN, the result is NaN.
Restrictions
-
The sequence must contain numbers. A sequence of another type is an error.
Examples
average([1, 2, 6])
Gives 3.
average(BT-13-Number) > 1000
| New in EFX-2. |