Aller au contenu

Photo

Modulo problem


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
Xardex

Xardex
  • Members
  • 217 messages
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?

#2
CID-78

CID-78
  • Members
  • 1 124 messages
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.

#3
CID-78

CID-78
  • Members
  • 1 124 messages
weird my reply doesn't show on my system.
% modulus is the leftover after a division
512%10 -> 2, 748%10 -> 8

#4
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages

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

#5
Xardex

Xardex
  • Members
  • 217 messages
Thanks for the info.