FEEL numeric functions: rounding, decimal, modulo

15 built-in functions · DMN 1.6

FEEL has a single number type, a decimal with 34 significant digits. There is no separate integer or float, and no binary floating point, so 0.1 + 0.2 is exactly 0.3. Most numeric questions in DMN modelling come down to two things: which of the seven rounding functions to use, and what happens when an operation is invalid. This guide answers both.

Each result was computed by the FEEL engine behind the evaluator at the top. Click Try it to run any example yourself.

All FEEL numeric functions at a glance

FunctionSignatureReturns
decimaldecimal(n, scale)Rounds n to the given scale using banker's rounding (round half to even)
floorfloor(n, scale?)Rounds towards negative infinity at the given scale
ceilingceiling(n, scale?)Rounds towards positive infinity at the given scale
round upround up(n, scale?)Rounds away from zero at the given scale
round downround down(n, scale?)Rounds towards zero at the given scale
round half upround half up(n, scale?)Rounds to the nearest value; ties round away from zero (the rounding most people learn in school)
round half downround half down(n, scale?)Rounds to the nearest value; ties round towards zero
absabs(n)Returns the absolute value of a number or duration
modulomodulo(dividend, divisor)Returns the remainder of the division
sqrtsqrt(number)Returns the square root; null for negative input
loglog(number)Returns the natural logarithm
expexp(number)Returns e raised to the given power
oddodd(number)Returns true if the number is an odd integer
eveneven(number)Returns true if the number is an even integer
numbernumber(from, grouping separator?, decimal separator?)Parses a string into a number, optionally describing which grouping and decimal separators the string uses

Numbers, equality and precision

Numbers compare by value, precision aside, so 1 = 1.0 and 1.10 = 1.1 are both true. Division is exact up to 34 significant digits. Comparing a number with a string is not false but null, because the two types cannot be compared.

1 = 1.0
returns true Try it ↑
0.1 + 0.2 = 0.3
returns true Try it ↑

Decimal arithmetic: no binary floating-point error.

1 / 3
returns 0.3333333333333333333333333333333333 Try it ↑

34 significant digits.

1000000000000000000000 + 1
returns 1000000000000000000001 Try it ↑

Large integers stay exact.

1 = "1"
returns null Try it ↑

Number and string cannot be compared, so the result is null, not false.

1 = number("1")
returns true Try it ↑

Negative numbers and **: -2 ** 2 is 4

In FEEL, arithmetic negation binds more tightly than exponentiation, which is the opposite of the convention in mathematics. DMN 1.6 says so explicitly: -4 ** 2 is (-4) ** 2, which is 16, not -16. The spec recommends always writing the parentheses.

-2 ** 2
returns 4 Try it ↑

Read as (-2) ** 2.

-(2 ** 2)
returns -4 Try it ↑

Parenthesize to get the mathematical reading.

Rounding: which function to use

FEEL has seven rounding functions, and they differ only in what they do with halves and negative numbers. decimal uses banker's rounding (half to even), the IEEE 754 default, which is not what most business users expect. For the rounding taught in school, use round half up. All of them take an optional scale, the number of decimal digits to keep. decimal requires it.

Each cell is the function applied to the row value with scale 0.
valuedecimalround half upround half downround upround downfloorceiling
2.52323223
3.54434334
-2.5-2-3-2-3-2-3-2
2.513333223
-2.49-2-2-2-3-2-3-2
decimal(2.345, 2)
returns 2.34 Try it ↑

Half to even: the 4 stays.

round half up(2.345, 2)
returns 2.35 Try it ↑

School rounding.

decimal(123.456, -1)
returns 120 Try it ↑

A negative scale rounds to tens, hundreds and so on.

floor(1.567, 2)
returns 1.56 Try it ↑

In short: round up and round down go away from and towards zero, while floor and ceiling go towards negative and positive infinity. They only disagree on negative numbers.

Division by zero and invalid input

FEEL has no exceptions. An operation that has no valid result, such as dividing by zero, the square root of a negative number or the logarithm of zero, evaluates to null. A string where a number is expected also gives null, with no implicit conversion. In the B-FEEL dialect, numeric built-ins return 0 wherever FEEL returns null (DMN 1.6, section 11.3).

1 / 0
returns null Try it ↑
modulo(10, 0)
returns null Try it ↑
sqrt(-1)
returns null Try it ↑
log(0)
returns null Try it ↑
floor("1.5")
returns null Try it ↑

Strings are not converted. Use number() first.

floor(number("1.5"))
returns 1 Try it ↑

Function reference

Each function with its parameters, examples and edge cases.

decimal(n, scale)

Rounds n to the given scale using banker's rounding (round half to even).

decimal rounds half to even, also called banker's rounding: 2.5 becomes 2 and 3.5 becomes 4. That avoids a systematic upward bias when many values are summed, but it surprises people checking an invoice by hand. Use round half up for school rounding.

ParameterTypeDescription
nnumberthe number to round
scalenumberdecimal digits to keep
decimal(1/3, 2)
returns 0.33 Try it ↑
decimal(1.5, 0)
returns 2 Try it ↑
decimal(2.5, 0)
returns 2 Try it ↑
decimal(2.345, 2)
returns 2.34 Try it ↑
decimal(2.355, 2)
returns 2.36 Try it ↑
decimal(-2.5, 0)
returns -2 Try it ↑
decimal(123.456, -1)
returns 120 Try it ↑

Negative scale rounds left of the decimal point.

decimal(1.5, null)
returns null Try it ↑

The scale is required.

Related: round half up · floor · ceiling

floor(n, scale?)

Rounds towards negative infinity at the given scale.

ParameterTypeDescription
nnumberthe number to round down
scalenumberdecimal digits to keep (optional, default 0)
floor(1.5)
returns 1 Try it ↑
floor(-1.56, 1)
returns -1.6 Try it ↑
floor(-1.5)
returns -2 Try it ↑

Towards negative infinity, so negative numbers move away from zero.

floor(null)
returns null Try it ↑

Related: ceiling · round down

ceiling(n, scale?)

Rounds towards positive infinity at the given scale.

ParameterTypeDescription
nnumberthe number to round up
scalenumberdecimal digits to keep (optional, default 0)
ceiling(1.5)
returns 2 Try it ↑
ceiling(-1.56, 1)
returns -1.5 Try it ↑
ceiling(-1.5)
returns -1 Try it ↑

Related: floor · round up

round up(n, scale?)

Rounds away from zero at the given scale.

ParameterTypeDescription
nnumberthe number to round
scalenumberdecimal digits to keep (optional, default 0)
round up(5.5)
returns 6 Try it ↑
round up(-5.5)
returns -6 Try it ↑
round up(1.121, 2)
returns 1.13 Try it ↑
round up(1.001)
returns 2 Try it ↑

Any fraction rounds away from zero.

Related: round down · ceiling

round down(n, scale?)

Rounds towards zero at the given scale.

ParameterTypeDescription
nnumberthe number to round
scalenumberdecimal digits to keep (optional, default 0)
round down(5.5)
returns 5 Try it ↑
round down(-5.5)
returns -5 Try it ↑
round down(1.999)
returns 1 Try it ↑

Truncates: everything after the scale is dropped.

Related: round up · floor

round half up(n, scale?)

Rounds to the nearest value; ties round away from zero (the rounding most people learn in school).

ParameterTypeDescription
nnumberthe number to round
scalenumberdecimal digits to keep (optional, default 0)
round half up(5.5)
returns 6 Try it ↑
round half up(-5.5)
returns -6 Try it ↑
round half up(2.345, 2)
returns 2.35 Try it ↑
round half up(-2.5)
returns -3 Try it ↑

Half rounds away from zero, for negative numbers too.

Related: round half down · decimal

round half down(n, scale?)

Rounds to the nearest value; ties round towards zero.

ParameterTypeDescription
nnumberthe number to round
scalenumberdecimal digits to keep (optional, default 0)
round half down(5.5)
returns 5 Try it ↑
round half down(-5.5)
returns -5 Try it ↑
round half down(2.5)
returns 2 Try it ↑
round half down(2.51)
returns 3 Try it ↑

Only an exact half rounds down.

Related: round half up · decimal

abs(n)

Returns the absolute value of a number or duration.

ParameterTypeDescription
nnumber or durationthe value
abs(-10)
returns 10 Try it ↑
abs(duration("-PT5H"))
returns PT5H Try it ↑
abs("x")
returns null Try it ↑

Related: modulo

modulo(dividend, divisor)

Returns the remainder of the division. The result has the sign of the divisor.

The result takes the sign of the divisor, as in floored division, not of the dividend as with the % operator in Java or JavaScript. Decimal operands work too.

ParameterTypeDescription
dividendnumberthe value to divide
divisornumberthe divisor, must not be 0
modulo(12, 5)
returns 2 Try it ↑
modulo(-12, 5)
returns 3 Try it ↑
modulo(-12, 5)
returns 3 Try it ↑

Sign of the divisor: positive.

modulo(12, -5)
returns -3 Try it ↑
modulo(10.5, 3)
returns 1.5 Try it ↑
modulo(10, 0)
returns null Try it ↑

Related: abs · even · odd

sqrt(number)

Returns the square root; null for negative input.

ParameterTypeDescription
numbernumberthe value; negative input yields null
sqrt(16)
returns 4 Try it ↑
sqrt(-1)
returns null Try it ↑
sqrt(0)
returns 0 Try it ↑
sqrt(2)
returns 1.414213562373095048801688724209698 Try it ↑

34 significant digits, like every FEEL number.

Related: exp · log

log(number)

Returns the natural logarithm.

ParameterTypeDescription
numbernumberthe value, must be positive
decimal(log(10), 4)
returns 2.3026 Try it ↑
log(0)
returns null Try it ↑
log(-1)
returns null Try it ↑

Related: exp · sqrt

exp(number)

Returns e raised to the given power.

ParameterTypeDescription
numbernumberthe exponent
decimal(exp(5), 4)
returns 148.4132 Try it ↑
exp(0)
returns 1 Try it ↑

Related: log · sqrt

odd(number)

Returns true if the number is an odd integer.

ParameterTypeDescription
numbernumberthe value to test
odd(5)
returns true Try it ↑
odd(2)
returns false Try it ↑
odd(null)
returns null Try it ↑

Related: even · modulo

even(number)

Returns true if the number is an even integer.

ParameterTypeDescription
numbernumberthe value to test
even(5)
returns false Try it ↑
even(2)
returns true Try it ↑
even(0)
returns true Try it ↑
even(-2)
returns true Try it ↑

Related: odd · modulo

number(from, grouping separator?, decimal separator?)

Parses a string into a number, optionally describing which grouping and decimal separators the string uses.

Without separator arguments only a plain number is accepted: an optional sign, digits, a dot as the decimal mark and an optional exponent. Thousands separators make the string invalid unless you name them.

ParameterTypeDescription
fromstringthe numeric string to parse
grouping separatorstringthousands separator used in the string (optional)
decimal separatorstringdecimal mark used in the string (optional)
number("1 000,5", " ", ",")
returns 1000.5 Try it ↑
number("1250.75")
returns 1250.75 Try it ↑
number("1,000")
returns null Try it ↑

A grouping separator has to be declared.

number("1,000.5", ",", ".")
returns 1000.5 Try it ↑
number("1.000,5", ".", ",")
returns 1000.5 Try it ↑

German and Swiss style.

number("1e3")
returns 1000 Try it ↑
number("12abc")
returns null Try it ↑

Related: string · decimal

How B-FEEL differs

In standard FEEL an invalid argument makes the result null. The business-friendly B-FEEL dialect returns a type default instead. Both columns were evaluated by the same engine:

ExpressionFEELB-FEEL
1 + nullnull1
1/0null0
"5" * 2null10
modulo(10, 0)null0
number("abc")null0

Every result on this page was computed by the Impulse FEEL engine 0.9.1, the interpreter that runs the playground. Last updated .

Defined by the OMG DMN 1.6 specification, chapter 10.3.4 (built-in functions).