If neither ios_base::fixed nor ios_base::scientific is set (this is the default),
the conversion specifier used is %g or %G (%gL or %GL for long double).
Let P equal the precision if nonzero, 6 if the precision is not specified, or 1 if the precision is 0. Then, if a conversion with style E would have an exponent of X:
if P > X ≥ −4, the conversion is with style f or F and precision P − 1 − X.
otherwise, the conversion is with style e or E and precision P − 1.
0.00001
P=6
X=5
P > X so style=f and precision=0.
I guess this means it should print the same as printf("%.0f", 0.00001) but it doesn't. If I instead change to printf("%.0e\n", 0.00001) it looks the same. Did I make a mistake somewhere?
All this becomes very technical. I was hoping there was a simpler explanation that explains what all these rules are trying to accomplish.
Is it somewhat correct to say that it uses scientific notation if it gives a shorter output or a more precise answer, using at most as many digits as specified by the precision, not counting digits in the exponent?
Ah, OK, thank you, so it becomes printf("%.5e\n", 0.00001) which prints 1.00000e-05. This is still wrong but hold on ...
Right after the text you quoted about %g it says the following.
Unless alternative representation is requested the trailing zeros are removed, also the decimal point character is removed if no fractional part is left. For infinity and not-a-number conversion style see notes.