note 46721 deleted from language.operators.comparison by googleguy

From: Date: Tue, 22 Oct 2013 06:52:39 +0000
Subject: note 46721 deleted from language.operators.comparison by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196686@lists.php.net to get a copy of this message
Note Submitter: darkcryst at gmail dot com ---- be REALLY careful when comparing float values. PHP, like most languages, is vunerable to he problems of floating point precision. Do NOT compare floats directly, and this also means any decimal value at all. The headaches finding out if $var = 0.3 caused me are unbelievable. even though the stored variable WAS 0.3 it was still ignoring it - this was to do with the internal float not recognising it as 0.3 even though it *displayed* it as 0.3 when echo'd or printed... basically it was stored imprecisly, but not able to display it as such. I ended up having to compare after multiplying by 10, rounding, and then dividing by 10... rediculous, but sadly the only way I could find to reliably do it. The round seemed to remove the break in the float... jesus that took me ages to find...

« previous php.notes (#196686) next »