NO

Author Topic: printf  (Read 3927 times)

Bastiaan

  • Guest
printf
« 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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2107
Re: printf
« Reply #1 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

 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


« Last Edit: June 11, 2008, 07:19:32 PM by timovjl »
May the source be with you

Bastiaan

  • Guest
Re: printf
« Reply #2 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;

}





Greg

  • Guest
Re: printf
« Reply #3 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.