# Thread: Splitting out large numbers

1. ## Splitting out large numbers

So I ran into a problem the other day and need to separate out a large number into small number groups for example:

945689234989910

needs to be split into

9456|8923|498|9910

and each group needs to be stored

Anyone have any ideas?

2. No code on your part means no code on my part.

However You could look into:
the string class
the substr method
and a simple for loop

3. Read it as text then convert the strings into integer values as needed.

4. Could it be more easily done with division and modulus?

5. Yes substr method would be the easiest way to do it. Read input as text, then use substr method of string. then convert evry slice using atoi function(or is there a C++ version?).

6. Could it be more easily done with division and modulus?
Yes, very easily.

Code:
```#include <iostream>

using namespace std;
int main()
{

int test;
test = 12345;

cout<< endl<< test%10 << " Last digit";
cout<< endl<< test%100 << " Last two digits";
cout<< endl<< test%1000 << " Last three digits" << endl;
//ect

return 0;
}```

7. Yes, very easily.
Ok give me the middle the 3rd set of 3 digits in:
945689234989910
probably won't be as easy as: str.substr(6,3);

The biggest concern I have about trying to keep everything as integral types is that:
945689234989910 is a lot larger than a 32 bit int can handle. So if you are on a system with that limitation then using the int datatype isn't going to work.

8. Bah, I did not even see the "more" part of what I quoted! Just showing it could be done.
It would not be very hard to pick the different parts out with that method; but your method is easier. I was just confirming with him that it could be done how he suggested.

9. So Enahs how could you pick the different parts out?

Thanks everyone for all the help

10. Using division / modulus is easist done when working from low values to high values:
Code:
```int main()
{
unsigned num = 123456789;
int i = 1000; // We want to print them in sets of 3 digits
while ( num > 0 )
{
cout << (num % i) << endl;
num /= i;
}
}```
I'll leave it to you to figure out how to go from high to low (there are several methods)

11. ## Array?

You could use a double char **. Sigh, it's a thought

Rogue