note 35591 added to language.types.float
| From: | gallico_ at hotmail dot com | Date: | Sun, 07 Sep 2003 12:34:18 +0000 |
| Subject: | note 35591 added to language.types.float | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-55573@lists.php.net to get a copy of this message | ||
To complete the thread about testing two floating point numbers for equality, here's the way it
works for *every* programming language:
<?php
// two fp numbers should be considered equal if their absolute
// difference does not exceed a certain value epsilon:
$epsilon = 0.0001; // this defines the precision of your comparision
// check their absolute difference
if (abs($one_float - $another_float) < $epsilon)
// what to be done in case the numbers are equal goes here
?>
----
Manual Page -- http://www.php.net/manual/en/language.types.float.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35591
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35591&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35591&report=yes