Solved

Easy Format Question

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 131
Turn a spreadsheet into a vba executable. 2 95
Process filename extension 3 196
maxBlock challenge 30 142
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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