Click to See Complete Forum and Search --> : Please elabrate what this means


jennAshton
04-03-2003, 04:45 PM
Math.round(mode / 10000 % 10)

it rounds the number to a whole number. But what's the 10000%10?

MikeOS
04-03-2003, 05:41 PM
The % is the modulo operator. It basically returns the remainder of a division. For instance:

10 % 4 would return 2, as 4 goes into ten twice, with a remainder of 2.

In their example it isn't so much what 10000 % 10 is doing, as, due to order of precedence, that isn't the sum. The division and modulo have equal precedence. So the order of evaluation is right to left. Meaning that in this example the value held by mode is divided by 10000 first, and then that value is modulo by 10, and the remainder is rounded. To be honest the expression mode / 10000 should be nested for cleaner programming. So it should be:

Math.round((mode / 10000) % 10)

As I said, it isn't necessary, it's just cleaner, so easier to understand.

pyro
04-03-2003, 05:53 PM
Originally posted by MikeOS
So the order of evaluation is right to left.Just to clarify (and I'm sure what you meant) is the order of evaluation is left to right...