This is the correct behavior.
For qualifiers a, A, e, E, f, and F: this is the number of digits to be printed after the decimal point.
For qualifiers g and G: this is the maximum number of significant digits to print. A.
If you use f instead of g , then it will work as you expected.
Code example
#include <stdio.h> int main(void) { printf("%.6g\n", 36.666666662); printf("%.6f\n", 36.666666662); return 0; }
Result
36.6667 36.666667
See how it works on the Internet: ideone .
source share