Thread: thousand seperator

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    India
    Posts
    14

    thousand seperator

    Is it possible to put thousand seperators for numebrs like:
    1,00,000.00
    I am declaring array as under
    Code:
    float stage_a[]={1000,2000,3000,5000,10000,
    		20000,40000,80000,160000,320000,
    		640000,1250000,2500000,5000000,10000000};
    Code:
    c=65,r=2;
    for(j=14;j>=0;j--)
     {
      gotoxy(c,r++);
      printf("%10.0f\n",stage_a[j]);
     }

    The display which i am geting is
    10000000

    5000000
    .
    .
    .
    .
    1000


    But I want to print the values as under
    1,00,000,000
    and so on



    thanx

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Yes, you can manipulate the values as character strings (arrays) and insert the commas in the appropriate places prior to final display.

    For a purely C++ method, I'd point you to the concept of locales and facets (num_put) but that's something of an advanced topic. A link to a thread describing this (the C++ method) that I did about a year ago is here.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Use %1000 and /1000 to extract groups of 3 decimal digits.

Popular pages Recent additions subscribe to a feed