"ai lian" <ai********@yah oo.com> wrote in message
news:9b******** *************** ***@posting.goo gle.com...
When I use printf to print a large double number, the result is not
the same as the original input number. For example:
double num=89999999999 9.894400;
printf("%lf\n", num);
The output is: 899999999999.89 4409
Could anyone tell me what the problem is? How can I get the right
output?
Normally %f is used for output, and not %lf.
In most implementations , and for most values, %f prints a reasonably number
of digits to round to the expected value. You seem to have found a case
where it doesn't.
Note that Java, for example, always prints enough digits so that when
converted back to internal format the same binary value is obtained. This
often means that the printed output disagrees with the user expectation, but
C doesn't normally do that.
Anyway, you got more digits than is normal for a double.
-- glen