Thread: commas in large numbers

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    commas in large numbers

    How would I insert commas into a large number such as 5.5E9?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    ?????

    5.500.000.000 or what?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    response to Magos

    Your little narative is as cryptic as the C language!!

    By the way my compiler is MSVC 6.0, and yes the number is
    5,500,000,000 or five point five billion, the population of the
    third planet from the sun.

    What I need is a comma inserting routine used in conjunction
    with the printf function. :-)

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Actually, the population is past six billion...

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Six billion? I did not know that ... simply wild ... weird wild stuff you find out from this board. Wacky.

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    re reply

    Originally posted by HKR
    Your little narative is as cryptic as the C language!!

    By the way my compiler is MSVC 6.0, and yes the number is
    5,500,000,000 or five point five billion, the population of the
    third planet from the sun.

    What I need is a comma inserting routine used in conjunction
    with the printf function. :-)
    I don't know what you mean by "inserting commas". Do you mean making the printout look like this:
    5.500.000.000 instead of 5500000000? I doubt there exists such a function, so you have to make your own. However, I don't have MSVC (see my signature) so I might be wrong though...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    okay I had same problem with an assignment I have just completed...though I didnot have to go as far as 5billion..I only needed it to go as far as 100,000,000. See if you could extend this, if you can understand the logic.

    this function prints a double value parameter, either positive or negative, to the display in format example 1,250.13.

    Code:
    void monetary_balance (double bal_val)
    {
      const long test1 = 100000000L, test2 = 100000L,
    	   grand = 1000L, tun = 100L;
      long 	   under100 = 0L, under1000 = 0L, undermill = 0L,
    	  convertval = 0L, overmill = 0L;
      char minus = ' ';
    
      if(bal_val < 0)   /* negative value ?*/
      {      /* converts to positive */
    	  bal_val -= (bal_val * 2);
    	  minus = '-';  /*minus sign for display or print */
      }
      bal_val *= 100;
      convertval = (long)bal_val;
    
      if(convertval >= test1)   /*over 999,999.99*/
      {
            under100 =  convertval % tun;
            under1000 = convertval % test2;
            under1000 = under1000 / tun;
            undermill = convertval / test2;
            undermill = undermill % grand;
            overmill = convertval / test1;
            printf("%c%3ld,%03ld,%03ld.%02ld", minus, overmill, undermill, under1000, under100);
           
      }
      else if(convertval >= test2)  /*over 999.99*/
            {
    	under100 =  convertval % tun;
    	under1000 = convertval % test2;
    	under1000 = under1000 / tun;
    	undermill = convertval / test2;
                    printf("%c%3ld,%03ld.%02ld ", minus, undermill, under1000, under100);
             }
            else      /*must be under 1000.00*/
             {
    	under100 =  convertval % tun;
    	under1000 = convertval % test2;
    	under1000 = under1000 / tun;
    	printf("%c    %3ld.%02ld ", minus,under1000,under100);		
            }
    }   /* end function monetary_balance */
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    hoping to be certified

    hey, bigtamscot, thanks for you time; finally a response that
    shows some programming expertise!! I can't say the same
    for the other responses to my post!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to deal wth large numbers
    By bvgsrs in forum C++ Programming
    Replies: 2
    Last Post: 06-18-2007, 06:16 AM
  2. Using really big numbers!
    By Machewy in forum C++ Programming
    Replies: 11
    Last Post: 02-26-2004, 10:49 AM
  3. Help needed with VERY large numbers.
    By jwarner in forum C++ Programming
    Replies: 4
    Last Post: 01-18-2004, 12:01 PM
  4. large numbers
    By Alextheking in forum C++ Programming
    Replies: 13
    Last Post: 01-09-2004, 03:51 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM