#### Archived

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

# How to split up an integer in different parts

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

## 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 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 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 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.

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009378
• ### Who's Online (See full list)

There are no registered users currently online

×