Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is c printf %f default precision?

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?

like image 898
spbots Avatar asked Jul 30 '09 16:07

spbots


2 Answers

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

If the precision is missing, 6 digits are given

like image 131
Laurence Gonsalves Avatar answered Oct 13 '22 22:10

Laurence Gonsalves


The default precision for %f is 6 digits (see ISO C99 specification, 7.19.6.1/7).

like image 38
Pavel Minaev Avatar answered Oct 13 '22 23:10

Pavel Minaev