TraderBoy
October 6th, 1999, 10:16 PM
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.
Oleg Lobach
October 7th, 1999, 05:47 AM
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.
TraderBoy
October 7th, 1999, 09:02 AM
Oleg, EXCELLENT! Thank you very much for your excellent solution to my problem.