There are two ways you could look at this.

(1) If they're rising from left to right then they're descending from right to left.
So modulo (%) the number with 10, record that, divide the test number by 10, repeat until the number is zero.

(2) Divide by 10, 100, 1000 etc as originally planned, but do it in a loop multiplying the number you divide by, by 10, until that power of 10 is greater than the number. So if you've got 1234, then you stop at 10000.

so: x=10
divide num by x
x*=10
repeat until x>num