|
-
July 28th, 1999, 04:01 AM
#1
another simple question
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?
-
July 28th, 1999, 04:20 AM
#2
Re: another simple question
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
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
|