4 ms·
C/C++: printf("%lf\n", 1000000 * 8.2); 8200000.000000 Here, printf() is doing the necessary rounding to hide the fact that 8.2 isn't exactly representab
by CamperBob2 14y ago
C/C++:
printf("%lf\n", 1000000 * 8.2);
8200000.000000
Here, printf() is doing the necessary rounding to hide the fact that 8.2 isn't exactly representable. It's interesting that other languages don't do something similar when outputting a float to text.
- pindi 14y agoThey do, you just have to request it: //Python >>> repr(1000000 * 8.2) '8199999.999999999' >>> "%lf" % (1000000 * 8.2) '8200000.000000'