Reputation: 73
I am a newbie in c.
If I try to print the sum of two double variables with 4.0 and 10.0, like:
printf("%lf", b+d); //b = 4.0 , d = 10.0
, the print isn't 14.0, it's 14 without decimals.
What should I do now?
Upvotes: 1
Views: 70
Reputation: 310910
You can write
printf( "%.1f", b + d );
the precision specifier (in the example above its value is 1
) after the point specifies the number of digits to appear after the decimal-point.
Upvotes: 4