Author Topic: Modulo problem  (Read 431 times)

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Modulo problem
« on: July 01, 2011, 10:43:37 am »


               gtg to work, no time to test.

iXP -= iXP %10


Does this return the lower number that is dividable by 10?
512->510
748->740

To my understanding (iXP %10) would return iXP, after it has been divided by 10 as many times as it can be without going decimals. Is this how modulos work, or am I completely off the track?
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
Modulo problem
« Reply #1 on: July 01, 2011, 11:21:16 am »


               modulos give you the leftover of a division ie 512%10 is 2, 748%10 is 8. because 510 is evenly dividable with 10. and your left with 2 that isn't. So a %10 will return a value between 0 and 9.

in your case you decrease iXP with a value between 0 and 9.
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
Modulo problem
« Reply #2 on: July 01, 2011, 11:24:21 am »


               weird my reply doesn't show on my system.
% modulus is the leftover after a division
512%10 -> 2, 748%10 -> 8
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Modulo problem
« Reply #3 on: July 01, 2011, 05:39:48 pm »


               

Xardex wrote...

gtg to work, no time to test.

iXP -= iXP %10


Does this return the lower number that is dividable by 10?
512->510
748->740

To my understanding (iXP %10) would return iXP, after it has been divided by 10 as many times as it can be without going decimals. Is this how modulos work, or am I completely off the track?

CID's answer is correct, and yes, that's what your code does.

Funky
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Modulo problem
« Reply #4 on: July 01, 2011, 09:06:39 pm »


               Thanks for the info.