Bug #71136 [Opn->Fbk]: periodic float numbers bug, works in php 5.6

From: Date: Wed, 16 Dec 2015 15:30:15 +0000
Subject: Bug #71136 [Opn->Fbk]: periodic float numbers bug, works in php 5.6
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197931@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71136&edit=1 ID: 71136 Updated by: laruence@php.net Reported by: djbrainnrg at gmail dot com Summary: periodic float numbers bug, works in php 5.6 -Status: Open +Status: Feedback Type: Bug Package: Unknown/Other Function Operating System: Windows10 64bit / Apache 2.4.x PHP Version: 7.0.0 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2015-12-16 15:29:40] laruence@php.net seems all php versions behavior same: https://3v4l.org/BrWp6 ------------------------------------------------------------------------ [2015-12-16 14:56:56] djbrainnrg at gmail dot com Description: ------------ Floating number precision in PHP 7 seems to be buggy or at least different to PHP 5.6. A simple calculation with a periodic number see testscript. This happens not with all periodic numbers. In PHP 5.6.x this works fine and output "8.2" as expected. In PHP 7.x this does NOT work and always output "8.199999999999", doesn't matter if you use round() with precision or not. Test script: --------------- ini_set("precision", (PHP_INT_SIZE == 4) ? 14 : 16); $nr = 8 + (1/10) + (9/90); var_dump($nr, round($nr, 2)); Expected result: ---------------- "8.2" for the rounded result on all systems. Actual result: -------------- "8.1999999999999" also with round() called ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71136&edit=1

« previous php.bugs (#197931) next »