Solved

Easy Format Question

Posted on 2004-03-21
4
176 Views
Last Modified: 2013-11-20
Hi

Using CString::Format how do I format 1234 to be 1,234
0
Comment
Question by:Dj_Fx8
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
info_expert earned 125 total points
ID: 10644630
There is no specific automatic method for this purpose in CString, but u can use your brain.
the len method of CString  returns the length of CString. you will do:

int groups=s1.len() /3;
CString s2;

now as you know the length of string

for(int c=len; c>3; c-=3)
{
//take the substring from s1 and put in s2 and then put the comma in s2.
//the length of s2 will be = s1.len() + groups;
}

Got?

Regards
0
 
LVL 5

Expert Comment

by:info_expert
ID: 10644652
One thing i forgot to tell that you can use the same string and use the 'insert' function to insert the commas in string but you will have to determine the number of groups of strings to be made in source string.
0
 

Author Comment

by:Dj_Fx8
ID: 10644717
Hi

>>>u can use your brain

I was hoping I wouldn't have to do that :-) I have no prob working it out, but just was wondering if there was an easier way.

Many Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10647737
Have a look at GetNumberFormat in help.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question