Monday, September 22, 2008

Converting double to a CString (0.005 to 5e-003)

Input:

double d = 0.005;

CString strTemp;

strTemp.Format("%.0e",d);

Output : 5e-003

But if I want “5e-03 then

Input:

// Enable two-digit exponent format

unsigned int old_exponent_format;

old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);

double d = 0.005;

CString strTemp;

strTemp.Format("%.0e",d);

Output : 5e-03

Conversion to scientific notation is done automatically. But as far as I know “5e-3” is impossible.

No comments: