C question

This might seem like a stupid question. But if I have
a variable declared as follows:

double a;
printf(“enter number”);
scanf("%lf",&a);
printf(“a=%lf”,a);

If I enter “a” as 1.1234567 i.e. 7 digits after the decimal point , it loses
precision and prints
a = 1.123457 i.e 6 digits after decimal point.
How do I get it to read 7 digits after the decimal point?

Thank you,
Shashank

Shashank <sbalijepalli@precitech.com> wrote:
: This might seem like a stupid question. But if I have
: a variable declared as follows:

: double a;
: printf(“enter number”);
: scanf("%lf",&a);
: printf(“a=%lf”,a);

: If I enter “a” as 1.1234567 i.e. 7 digits after the decimal point , it loses
: precision and prints
: a = 1.123457 i.e 6 digits after decimal point.
: How do I get it to read 7 digits after the decimal point?

Are you printing the value with enough precision? The docs state that the
default precision for ‘f’ is 6 decimal places, and they don’t say that the
‘l’ changes that.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Previously, Shashank wrote in qdn.public.qnx4:

This might seem like a stupid question. But if I have
a variable declared as follows:

double a;
printf(“enter number”);
scanf("%lf",&a);
printf(“a=%lf”,a);

If I enter “a” as 1.1234567 i.e. 7 digits after the decimal point , it loses
precision and prints
a = 1.123457 i.e 6 digits after decimal point.
How do I get it to read 7 digits after the decimal point?

Thank you,
Shashank

printf(“a = %.7lf\n”, a);

Paul.