Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with CString::Format()

Status
Not open for further replies.

WilliamGS

Programmer
Jan 21, 2004
54
PE
Hi all. I am using CString::Format() to convert a double to string:

CString str;
str.Format("%f", 3.14); //The result is "3.14000000" ==> I want "3.14"
str.Format("%f", 202.141); //The result is "202.14100000" ==> I want "202.141"

I do not want the nonsignificant zeros. Is there a way to convert a double to string avoiding nonsignificant zeros?.

Thanks in advance,
William GS.
 
Format it as:

str.Format("%.2f", 3.14); //2 place precision

str.Format("%.3f", 202.141); //3 place precision

 
Hi,
>> str.Format("%.2f", 3.14); //2 place precision
>> str.Format("%.3f", 202.141); //3 place precision

It works fine, but I don't know the precision, it could be 0, 1, 2, 3, 4, ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top