## C and C++

Moderators: None (Apply to moderate this forum)
Number of posts: 94715

This Forum Only

Re: How can i add commas to certain numbers Posted by Xotor on 29 Jan 2001 at 11:06 PM
Sometimes it is just easier to use a little figuring out beforehand and then bruteforce the result.

1,234 has one
12,345 has two
123,456 has three

Okay, now you have that. Now, say for example you have two digits on the end.

Write out the first two digits of your number and then add a comma. Something like,

cout << Number.substr (0,2);

Then output a comma,

cout << ",";

and then output three more digits and a comma, and continue doing that until you reach the end of the string. You don't even need to know how many digits are actually in your string to begin with, only how many are on the very left.

-Xotor-

Michelle How can i add commas to certain numbers on 29 Jan 2001 at 12:49 PM
Mike Re: How can i add commas to certain numbers on 29 Jan 2001 at 12:55 PM
Eric Tetz Re: How can i add commas to certain numbers on 29 Jan 2001 at 2:48 PM
Michelle Re: How can i add commas to certain numbers on 29 Jan 2001 at 9:50 PM
Xotor Re: How can i add commas to certain numbers on 29 Jan 2001 at 11:06 PM
Michelle Re: How can i add commas to certain numbers on 29 Jan 2001 at 11:40 PM
Xotor Re: How can i add commas to certain numbers on 30 Jan 2001 at 2:04 AM
Michelle Re: How can i add commas to certain numbers on 30 Jan 2001 at 12:09 AM
Eric Tetz Re: How can i add commas to certain numbers on 30 Jan 2001 at 1:22 AM
Michelle Re: How can i add commas to certain numbers on 30 Jan 2001 at 7:36 AM
Eric Tetz Re: How can i add commas to certain numbers on 30 Jan 2001 at 10:47 AM
Naomarik Re: How can i add commas to certain numbers on 22 Feb 2009 at 1:28 PM
MVE120_college Re: How can i add commas to certain numbers on 29 Nov 2012 at 12:12 PM
MVE120_college Re: How can i add commas to certain numbers on 29 Nov 2012 at 12:53 PM
MVE120_college Re: How can i add commas to certain numbers on 29 Nov 2012 at 12:55 PM
MVE120_college Re: How can i add commas to certain numbers on 29 Nov 2012 at 12:57 PM
MVE120_college Re: How can i add commas to certain numbers on 29 Nov 2012 at 1:55 PM

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic