All the three format specifiers %e, %f and %g are used to work with float and double data types in C.
%e
represents the data in exponential power(scientific format).
%f
represents the data in normal decimal form, upto six decimal places, although you can control, that upto how many decimal places did you want your output.
%g
represents the decimal format and removes succeeding zeros.
example how to use %e, %f and %g in a c code:
#include <stdio.h>
int main()
{
double ans = 123.45;
printf("Printing using %%f %f\n",ans);
printf("Printing using %%e %e\n",ans);
printf("Printing using %%g %g\n\n\n",ans);
//
ans = 123.45e8; // scientific way of writing 123.45 * 10^8
printf("Printing using %%f %f\n",ans);
printf("Printing using %%e %e\n",ans);
printf("Printing using %%g %g\n\n\n",ans);
ans = 123.45e-8; // scientific way of writing 123.45 * 10^(-8) i,e. 0.0000012345
// %f has upto 6 digits precision
// 0.0000012345 converted to 0.000001 (max 6 precision allowed)
printf("Printing using %%f %f\n",ans);
printf("Printing using %%e %e\n",ans);
printf("Printing using %%g %g\n",ans);
return 0;
}
the output would be:
Printing using %f 123.450000
Printing using %e 1.234500e+02
Printing using %g 123.45
Printing using %f 12345000000.000000
Printing using %e 1.234500e+10
Printing using %g 1.2345e+10
Printing using %f 0.000001
Printing using %e 1.234500e-06
Printing using %g 1.2345e-06