number
title: Number sidebar_position: 3
Number
Part of the function and operator catalog. Every example shown below is
executed as an assertion by the engine's own test suite (examples.test.ts), so a result shown
here is a result the engine actually produces for that input.
ABS
ABS(value: a number) -> a number
Returns a number's absolute value, keeping its original number of decimal places.
Examples:
ABS(-1.500)- result:
"1.500"
- result:
ABS(5)- result:
"5"
- result:
ROUND
ROUND(value: a number, places: a number, mode?: text) -> a number
Rounds a number to a declared number of decimal places. Defaults to commercial rounding (half-up, away from zero) unless an explicit rounding mode is given as the third argument. The places argument must not be negative.
Examples:
ROUND(2.345, 2)- result:
"2.35"
- result:
ROUND(input.amount, 2)- context:
{"amount":-2.345} - result:
"-2.35"
- context:
ROUND(2.5, 0, 'half-up')- result:
"3"
- result:
ROUND(2.5, 0, 'half-even')- result:
"2"
- result:
ROUND(2.5, 0, 'half-down')- result:
"2"
- result:
ROUND(2.5, 0, 'up')- result:
"3"
- result:
ROUND(2.5, 0, 'down')- result:
"2"
- result:
ROUND(2.5, 0, 'ceil')- result:
"3"
- result:
ROUND(2.5, 0, 'floor')- result:
"2"
- result:
ROUND(1, 0, 'bogus')- fails with
EXPR_INVALID_ROUNDING_MODE
- fails with
ROUND(1, -1)- fails with
EXPR_TYPE_MISMATCH
- fails with
PARSENUMBER
PARSENUMBER(text: text, format: text) -> a number
Reads a piece of text as a number, in one of three named formats: 'plain' (a dot decimal separator, no grouping), 'de' (a comma decimal separator, a dot grouping separator), or 'en' (a dot decimal separator, a comma grouping separator). This is the engine's only string-to-number conversion — a string is never guessed at. A single leading '+' or '-' sign and leading zeros are both accepted; no whitespace is accepted anywhere. The result's scale is the number of digits after the decimal separator in the source text.
Examples:
PARSENUMBER('1234.56', 'plain')- result:
"1234.56"
- result:
PARSENUMBER('1234.56', 'en')- result:
"1234.56"
- result:
PARSENUMBER('1234,56', 'de')- result:
"1234.56"
- result:
PARSENUMBER('1,234.56', 'en')- result:
"1234.56"
- result:
PARSENUMBER('1.234,56', 'de')- result:
"1234.56"
- result:
PARSENUMBER('1.234,56', 'en')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('1,234.56', 'de')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('1,234.56', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('1,23,456', 'en')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER(',234.56', 'en')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('234,.56', 'en')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('1,,234', 'en')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('-1234.50', 'plain')- result:
"-1234.50"
- result:
PARSENUMBER('+5', 'plain')- result:
"5"
- result:
PARSENUMBER('-', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('1-', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('--5', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('007.5', 'plain')- result:
"7.5"
- result:
PARSENUMBER('1.', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('.5', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('1.2.3', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER(' 1', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('1 ', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('12a', 'plain')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with
PARSENUMBER('1.50', 'plain')- result:
"1.50"
- result:
PARSENUMBER('1234.56', 'nonsense')- fails with
EXPR_NUMBER_PARSE_FAILED
- fails with