#43640 [Opn->Csd]: Wrong Result Adding Float (2.8 not 2.8)

From: Date: Thu, 20 Dec 2007 02:11:26 +0000
Subject: #43640 [Opn->Csd]: Wrong Result Adding Float (2.8 not 2.8)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120765@lists.php.net to get a copy of this message
ID: 43640 User updated by: tyokoo at monadel dot com dot au Reported By: tyokoo at monadel dot com dot au -Status: Open +Status: Closed Bug Type: Math related Operating System: Windows2003R2 Standard PHP Version: 5.2.5 New Comment: See FYI: http://au.php.net/float Previous Comments: ------------------------------------------------------------------------ [2007-12-20 01:04:05] tyokoo at monadel dot com dot au Description: ------------ If you assign 2.8 on PHP you get: 2.79999999999999982236431605997495353221893310546875 if you do: $n = 2.8; $n = $n+$n+$n+$n+$n+$n+$n+$n+$n+$n; and compare: $n == 28 will be false. 2.8 is 2.8. Nothing more or less. Reproduce code: --------------- $n = 2.8; echo serialize($n).'<br />'; $n = $n+$n+$n+$n+$n+$n+$n+$n+$n+$n; if ($n == 28) { echo 'right'; } else { echo 'wrong'; } Expected result: ---------------- d:2.8; right Actual result: -------------- d:2.79999999999999982236431605997495353221893310546875; wrong ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43640&edit=1

« previous php.bugs (#120765) next »