The behaviour is defined by the standard (see
fprintf[
^]):
Quote:
The exponent shall always contain at least two digits. If the value is zero, the exponent shall be zero.
So the only solution would be printing to a buffer using
sprintf()
and modifying the string afterwards.
Example:
char buffer[64];
sprintf(buffer, "%E", num);
char *expPos = strchr(buffer, 'E');
int exp = atoi(expPos + 1);
sprintf(expPos + 1, "%+d", exp);
printf(buffer);
[EDIT]
A version that removes also trailing zeroes before the exponent:
char buffer[64];
sprintf(buffer, "%E", num);
char *expPos = strchr(buffer, 'E');
int exp = atoi(expPos + 1);
do expPos--; while (expPos > buffer && *expPos == '0');
sprintf(expPos + 1, "E%+d", exp);
printf(buffer);
[/EDIT]