Hacker News new | comments | show | ask | jobs | submit login

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.



They do, you just have to request it:

    //Python
    >>> repr(1000000 * 8.2)
    '8199999.999999999'
    >>> "%lf" % (1000000 * 8.2)
    '8200000.000000'




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: