Solved

Easy Format Question

Posted on 2004-03-21
4
174 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now