Archived

This topic is now archived and is closed to further replies.

How to split up an integer in different parts

This topic is 5131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I split up an integer in different parts? For example how do I get an integer 731245 to 73, 12 and 45? I can''t figure it out how to operate it. int sum = 731245; short a, b, c; a = ? b = ? c = ? (ex.)134578 integer to 13, 45 and 78? ------------------------------- Anton Karlsson Klingis Entertainment Games with silly humor Aleph One (Marathon Open Source) | My Homepage Packa bajs med winzip! Just dreaming wont make you (more) skilled in game programming/development.

Share this post


Link to post
Share on other sites
do you mean how do you divide it up into units, tens, hundreds, thousands etc?

if you do

int remainder = sum % 10;

it gives you the remainder as a result of dividing by ten. That should point you in a useful direction.

% is the modulus operator. There is a whole branch of mathematics concerning number theory which comes up with some amazing theories and proofs using modulo.

Share this post


Link to post
Share on other sites
c = sum % 100;
sum /= 100;
b = sum % 100;
a = sum / 100;


(I think ... LOL)



"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

Share this post


Link to post
Share on other sites
Yes, It''s right! thanks!

I got the idea to multiply by 0.01 (b = sum * 0.01)

-------------------------------
Anton Karlsson
Klingis Entertainment
Games with silly humor

Aleph One (Marathon Open Source) | My Homepage

Packa bajs med winzip!

Just dreaming wont make you (more) skilled in game programming/development.

Share this post


Link to post
Share on other sites