# Thread: Digit Separation like for 10000 - 10/000

1. ## Digit Separation like for 10000 - 10/000

How can i do this?Any ideas and codes will be appreciated.(I am a newbie sorry)

2. Yes, simply use sprintf to print your number into a string. Then having that string, you can seperate it any way you want as each individula digit will be a character.

3. You might be able to do this with the localization stuff.

Check this out:

http://www.opengroup.org/onlinepubs/.../locale.h.html

Otherwise, manually, do it with sprintf() or snprintf(), which was already suggested.

4. nope i did not explain well.
Here is the my codes:
Code:
```int main ()
{
int pid;
pid = getpidmap(); // now pid = 10540 or something.
printf("The software running count is &#37;d", assort_digit(pid)); // The software running count is 10.540
exit(0);
}
int assort_digit (int pid)
{
...
return pid; //this is assorting
}```
I don't know how can i write assort_digit func.
input: 10000 output must be: 10.000
input: 7876 output must be: 7.876
i hope you got it sorry.

5. Same answer as what I just last said.

An int can't be formated to print a specific style. It's just an int. To the computer, a number is just a number. Commas and periods or any other punctuation are pointless and ignored.

You have to convert it to a string, because a string can be formatted since it's just text.

If this makes no sense to you, then you have to conquor the concept that a number is just a number. 1234 is 1,234 is 0000000001234 in math. The computer will see it all in binary format. It just stores each bit, it doesn't care about commas. Ask yourself how you think the computer stores a number like 5 inside RAM. Then move on to a number like 1,234. Then ask yourself how it can tell the difference between 1234 and 1,234.

6. I don't know how can i write assort_digit func.
input: 10000 output must be: 10.000
input: 7876 output must be: 7.876
i hope you got it sorry.
I don't see what that has to do with number formatting, but 10,000 / 1000 = 10, and 7,876 / 1000 = 7.876

So assort_digit() could return whatever divided by 1000.

As for digit grouping, it depends on what sort of grouping you opt to go for as MacGyver said, see locale.h - I think 10,000 is French digit grouping or something.

Popular pages Recent additions