Pelles C forum

C language => Beginner questions => Topic started by: Bastiaan on June 11, 2008, 01:32:09 PM

Title: printf
Post by: Bastiaan on June 11, 2008, 01:32:09 PM
printf("%lf ", variable);

this will by default print with 6 digits after the decimal point.
I noticed the result is rounded by Pelles C (version 4.5).
Other compilers just truncate the result.

Could anyone please clarify this??

Bastiaan
Title: Re: printf
Post by: TimoVJL on June 11, 2008, 07:17:20 PM
Please show us example code or least what variable value was.


Read this:

http://www.opengroup.org/onlinepubs/009695399/functions/printf.html (http://www.opengroup.org/onlinepubs/009695399/functions/printf.html)

 If the precision is missing, it shall be taken as 6;

L
    Specifies that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument.

Here is more about C standard:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf)


Title: Re: printf
Post by: Bastiaan on June 12, 2008, 01:18:12 AM
#include <stdio.h>
#include <stdlib.h>

int main()
{

printf("The true variance is %lf\n", 0.0000016 );

return 0;

}




Title: Re: printf
Post by: Greg on August 15, 2008, 06:32:35 PM
Quote from: timovjl
L  Specifies that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument.

He is using a lowercase l, which is correct for a double, but optional for printf.

l (ell) Specifes that a following a, A, e, E, f, F, g, or G conversion specifier applies to an argument with type pointer to double.
 
I realize this is an old post but I couldn't let it go.