??? Displaying dollar amount in edit box?
Okay, I'm feeling pretty stupid because I can't seem to display a float variable as a dollar amount in a dialog's edit box. (10.00 reads as 10) I thought this would be a simple procedure, but I can't find any Visual C++ support for this, at least I haven't had luck with the online materials or books I've checked. I would appreciate any suggestions.
"Try not. Do, or do not. There is no try." - Yoda
Re: ??? Displaying dollar amount in edit box?
If you are using the string then try to concatenate it and then display other wise in double this seems difficult.
Re: ??? Displaying dollar amount in edit box?
I have been down this road!
There are a handful of classes on this site for formating numerical values as a dollar, that is, including the $ and making sure that their are 2 and only 2 decimal places. I have found that this classes suck. Each has it's own unique flaw.
The easiest way to format a number as a dollar amount is to use
GetDlgItemText(IDC_EDIT, m_edit);
then do something like
double value = atof(m_edit);
char buf[256];
sprintf(buf, "%.2f", value);
SetDlgItemText(IDC_EDIT, buf);
Typing %.2f forces it to be 2 decimal places. You could include the $ symbol but it tends to clutter the output - I like to just see numbers. You would want to put these commands in the OnChange or OnUpdate() functions.
Please email me if you have any problems with this code.