DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: number format

  1. #1
    cal Guest

    number format


    Hello--I am trying to format numbers so they appear 111,111,111,111 (with
    the commas at the
    thousands place. Is there a defined function that will format the numbers
    with the commas?


    thanks in advance


    cal

  2. #2
    Jim Argeropoulos Guest

    Re: number format


    "cal" <sticks2@earthlink.net> wrote:
    >
    >Hello--I am trying to format numbers so they appear 111,111,111,111 (with
    >the commas at the
    >thousands place. Is there a defined function that will format the numbers
    >with the commas?
    >
    >
    >thanks in advance
    >
    >
    >cal

    I don't know of one in the standard off the top of my head, but this should
    work (or something close to it, since I just typed it out).

    string&
    LongToCommaFormatString (
    string& outResult ,
    long inSource )
    {
    outResult = "" ; // For safety

    char aBuffer [ 255 + 1 ] ;
    char* aIndex = aBuffer ;
    int i = 0 ;
    while ( inSource )
    {
    *aIndex = inSource % 10 + '0' ;
    inSource /= 10 ;
    ++aIndex ;
    ++i ;
    if ( i % 2 )
    {
    *aIndex = ',' ;
    ++aIndex ;
    }
    }
    while ( aIndex-- != aBuffer )
    {
    outResult += *aIndex ;
    }
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links