|
-
October 6th, 1999, 10:16 PM
#1
CEdit
I have a CViewForm with some read-only CEdit controls of which their dollar values are initiated from calls to the doc. What is the easiest way to format the controls to show commas, i.e., the value 5555.45 is loaded into the control . . what it to appear as 5,555.45. Thanks for any suggestions.
-
October 7th, 1999, 05:47 AM
#2
Re: CEdit
Hi,
Create handler for EN_UPDATE class like this:
CString strText;
CString strNewText;
m_Edit.GetWindowText(strText);
int nTextLength=strText.GetLength();
int nPoint=strText.Find('.');
int nCommas=nPoint/3;
int nFirstComma=nPoint%3;
if(nPoint==-1)
{
nCommas=nTextLength/3;
nFirstComma=nTextLength%3;
}
else
{
nCommas=nPoint/3;
nFirstComma=nPoint%3;
}
if(!nFirstComma)
{
--nCommas;
nFirstComma=3;
}
CString strTemp;
strTemp=strText.Mid(0,nFirstComma);
strNewText=strTemp+',';
for(int i=0;i<nCommas-1;i++)
{
strTemp=strText.Mid(nFirstComma+i*3-1,3);
strNewText=strTemp+',';
}
strNewText=strNewText+strText.Right(nTextLength-nPoint);
m_Edit.SetWindowText(strNewText);
Hope this helps,
Oleg.
-
October 7th, 1999, 09:02 AM
#3
Re: CEdit
Oleg, EXCELLENT! Thank you very much for your excellent solution to my problem.
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
|
Click Here to Expand Forum to Full Width
|