The mod operator cannot calculate a negative value

0
Hi,   I was trying to find the result of the operation -2 mod 10, which is 8. Then I realized Mendix go wrong answer, it found -2 mod 10 = -2.   Yes, I am aware that I can find the correct result by adding the powers of 10 to -2, but I am not interested in that. With what other operator or in what way can I find the correct remainder when dividing the values ​​by a number?
asked
2 answers
0

This is based on the Java modulus operator, which is really a remainder operator. 

 

As you said, the solution is to check if the answer is negative, and if it is, then you need to add the divisor to the result.

 

You can abstract this to a sub microflow and use that when calculating modulus so you have a single piece of shared code that behaves as you expect throughout your application.

 

I hope this helps. 

answered
1

Hi AYBERK AKBALIK,

you can use this logic,

$Dividened - floor($Dividened div $Divisor)* $Divisor

(-2)- floor(-2 div 10) * 10

answered