Digit Separation like for 10000 - 10/000

This is a discussion on Digit Separation like for 10000 - 10/000 within the C Programming forums, part of the General Programming Boards category; How can i do this?Any ideas and codes will be appreciated.(I am a newbie sorry)...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    32

    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. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    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.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    32
    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 %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.
    Last edited by |HBO|; 08-26-2007 at 07:43 AM. Reason: typo

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    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.
    Last edited by zacs7; 08-27-2007 at 12:43 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error msg instead of the result so far
    By maybabier in forum C Programming
    Replies: 25
    Last Post: 03-20-2009, 02:45 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Adding a Large number digit by digit
    By mejv3 in forum C Programming
    Replies: 1
    Last Post: 09-14-2007, 03:28 AM
  4. newbie programmer - needs help bad.
    By hortonheat in forum C Programming
    Replies: 17
    Last Post: 10-20-2004, 05:31 PM
  5. Roman number converter
    By BalanusBob in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2002, 06:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21