%g doesn't print as many decimal places as %f

Take a look at this:

Code:

`int main() {`

double x, y;

x = 5;

y = 2.75;

printf("x is %f and y is %f\n", x, y);

return(0);

}

That will print 'x is 5.00000000 and y is 2.7500000000000' or somesuch.

I wanted to get rid of the useless zeroes, so somebody suggested using %g instead. Problem is, that rounds to the nearest ten thousanth (four decimal places), while %f works to six (nearest millionth).

Any ideas? If possible, I'd like to retain the functionality of %g but have six significant decimal places.