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

> I think the reason that 0.1 + 0.2 prints out 0.3 in PHP is that PHP’s algorithm for displaying floating point numbers is less precise than Python’s

It's a display thing, not an algorithm thing. It rounds by default at a certain length, previously 17 digits.

    php > echo PHP_VERSION;
    8.2.1
    php > $zeropointthree = 0.1 + 0.2;
    php > echo $zeropointthree;
    0.3
    php > ini_set('precision', 100);
    php > echo $zeropointthree;
    0.3000000000000000444089209850062616169452667236328125
https://www.php.net/manual/en/ini.core.php#ini.precision



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: