How can I use printf in C to display the full length of a double.
Consider
int main(){
double x = 0.00000000000001;
printf("x: %f \n", x);
}
The result I get is "i: 0.000000", however from what I read %f is the correct format specifier and doubles should have 15-17 significant figures therefore I don't understand why I am getting a rounded result. I have also tried things like %15f and %lf.
I am using Ubuntu if that helps.
From http://linux.die.net/man/3/printf:
f, F
The double argument is rounded and converted to decimal notation in the style [-]ddd.ddd, where the number of digits after the decimal-point character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly zero, no decimal-point character appears. If a decimal point appears, at least one digit appears before it.
If you want to output 15 digits after the decimal points, it should be %.15f instead of %15f:
printf("i: %.15f \n", i);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With