Calculating the remainder of a division

Mar 26, 2018

Hi All,

Is there a way to calculate and assign the remainder of a division calculation to a variable?

Say if I divide 10 by 4, I should be able to assign the remainder value 2 to a new variable.

Thanks,

Senthil R

2 Replies
Walt Hamilton

For anybody that is interested in this sort of challenge, this sample does it with SL triggers, using repeated subtraction.

The problem is that if the first number is too big, it doesn't complete the process. Set number 1 to 1000 and number 2 to 5 or less, and the process ends before finishing. I thought it was because Slide 1 is recursive, and its iterations exceeded SL's ability to keep track. But Slide 2 isn't recursive and it processes more iterations, and still halts before completing. I conclude that the calling process and the action take different amounts of time, and eventually one simply outruns the other with the result that the cycle is broken on both slides.

I solved the problem by introducing a pause on slide 3 in the form of an animation, but the minimum length of an animation is 0.1 sec which is too slow.

 I tried using a layer timeline (slide 4) because they can be set to .01 sec, but showing the layer apparently takes more time and gives only about 120 iterations.

So unless you have fewer than about 220 iterations (for the slide 1 method) or 250 (for the slide 2 iteration), Javascript is your best bet.

The sample is included for anybody that wants play with it and find a method of doing this using only triggers.

This discussion is closed. You can start a new discussion or contact Articulate Support.