note 117212 added to language.types.float

From: Date: Mon, 04 May 2015 00:06:38 +0000
Subject: note 117212 added to language.types.float
Groups: php.notes 
Request: Send a blank email to php-notes+get-202419@lists.php.net to get a copy of this message
An effective way to compare two real numbers (including floating point numbers) with high accuracy and still be able to set precision is using the BC Math function bccomp(); For instance: <?php $a = 1.23456789; $b = 1.23456780; $precision = 5; if(bccomp($a, $b, $precision) === 0 ) { echo "true"; } // true ?> <?php $a = sprintf('%.17f', 0.1+0.2); $b = 0.3; if(bccomp($a, $b, 17) !== 0 ) { echo "FALSE"; } // FALSE ?> ---- Server IP: 72.52.91.14 Probable Submitter: 187.21.248.94 ---- Manual Page -- http://php.net/manual/en/language.types.float.php Edit -- https://master.php.net/note/edit/117212 Del: integrated -- https://master.php.net/note/delete/117212/integrated Del: useless -- https://master.php.net/note/delete/117212/useless Del: bad code -- https://master.php.net/note/delete/117212/bad+code Del: spam -- https://master.php.net/note/delete/117212/spam Del: non-english -- https://master.php.net/note/delete/117212/non-english Del: in docs -- https://master.php.net/note/delete/117212/in+docs Del: other reasons-- https://master.php.net/note/delete/117212 Reject -- https://master.php.net/note/reject/117212 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202419) next »