DataWeave Delight: Calculating Remainder After Division
To calculate the modulo of two numbers in DataWeave we can use the mod
function from the dw::Core
module. We provide two arguments where the first argument is the number that needs to be divided by the number provided as second argument. The number that remains after a division of the input arguments is returned as a result.
In the following example we use different arguments for the mod
function:
Source
%dw 2.0
output application/json
---
{
result1: 6 mod 3,
result2: 5 mod 3,
result3: 5 mod -3,
result4: -5 mod 3,
result5: -5 mod -3,
result6: 1.5 mod 1,
result7: 5.095 mod 3
}
Output
{
"result1": 0,
"result2": 2,
"result3": 2,
"result4": -2,
"result5": -2,
"result6": 0.5,
"result7": 2.095
}
Written with DataWave 2.4.
DataWeave is a functional language designed by MuleSoft for transforming data structures defined in for example JSON, XML or CSV. |