Shop OBEX P1 Docs P2 Docs Learn Events
How does modulus division work in this case? — Parallax Forums

How does modulus division work in this case?

cthomascthomas Posts: 17
edited 2013-01-15 21:52 in Propeller 1
I came across this on the forum looking for how to extract a digit from a multi-digit number and when I first read it, I had no idea how it would work.

"Welcome to the insanely fun world of Propeller!!
If you need to extract the numbers to format it as a string you can use the readily available objects (numbers and simple_numbers).
Moreover if you check the objects you'll find a lot of code to handel that.
Anyway the solution is to combine / and // (the two division operators).
If you take 5678, and want to extract the 3rd digit, you can do something like that:
(5678/10)//10
5678/10 gives 567 (you must set the right power of 10 to extract the right digit)
567//10 gives 6 (this part applies in every case)"

To get the 6, shouldn't this be.... (5678/100)//10 ?

Thanks.

Comments

  • SRLMSRLM Posts: 5,045
    edited 2013-01-15 21:45
    Yes, it should be divide by 100 instead of 10.
  • cthomascthomas Posts: 17
    edited 2013-01-15 21:52
    Thanks. It seemed obvious after I thought about it, but several replies to the stuff I'm quoting acted like the quote was correct.

    I appreciate it.

    Craig
Sign In or Register to comment.