Link to home
Start Free TrialLog in
Avatar of voloshin
voloshin

asked on

float to CString conversion - not with gcvt!!!

I need to convert float a=0.000432 to CString. Using gcvt function results in 4.32 E-4.
But I need to keep it in the same form "0.000432" and not to use exponential presentation.
Any help?
Thanks,
Alex
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nabehs
nabehs


char szBuffer[24];
float nNumber = 0.000432;

sprintf(szBuffer, "%0.6lf", nNumber)
CString strNumber = szBuffer;

Why use an additional variable?
because %f does not work in CString::Format. You have to use sprintf for converting floats.
Avatar of voloshin

ASKER

Thanks for good advice, str.Format("%.6f",a) provides exactly 6 places after the dot.