-
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
-
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 ;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks