What is c printf %f default precision?

0 votes
asked Jul 30, 2009 by spbots

I'm curious:

If you do a printf("%f", number); what is the precision of the statement? I.e. How many decimal places will show up? Is this compiler dependent?

3 Answers

0 votes
answered Jul 30, 2009 by laurence-gonsalves

The ANSI C standard, in section, says this about the f format specifier:

If the precision is missing, 6 digits are given

0 votes
answered Jul 30, 2009 by pavel-minaev

The default precision for %f is 6 digits (see ISO C99 specification,

0 votes
answered Jul 30, 2009 by karl-voigtland

The book, C: A Reference Manual states that if no precision is specified then the default precision is 6 (i.e. 6 digits after the decimal point).

One caveat is if the number is inf (i.e. 1.0/0.0) or NaN then C99 specifies that the output should be inf, -inf, infinity, -infinity, or nan etc....

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter