I have this code:
float myFloat = 100.520920
CString myString;
myString.Format("%f",myFloat);
I want the string to display 100.52 (limit to two decimal places)
how can I do this?
Printable View
I have this code:
float myFloat = 100.520920
CString myString;
myString.Format("%f",myFloat);
I want the string to display 100.52 (limit to two decimal places)
how can I do this?
Hi,
myString.Format("%.2f",myFloat);
The number after the dot is the count of the decimal places. Format ist calling sprintf, it will be rounded. 0.4999 will be 0, 0.5 will be 1.
BTW, if you're writing a "real" application (not just for learning)you need to take care of the regional settings. Some countries use a comma as decimal point.
Martin