note 89348 deleted from function.floor by thiago

From: Date: Wed, 04 Mar 2009 11:46:30 +0000
Subject: note 89348 deleted from function.floor by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151443@lists.php.net to get a copy of this message
Note Submitter: elar at trigger dot ee ---- <?php $no1 = 930; $no2 = 18.6; $result = $no1 / $no2; var_dump($result); // float(50) // BUT! floor($result); // float(49) ?> "Returns the next lowest integer value by rounding down value if necessary." Maybe 930 / 18.6 is something like 49.99999999999999999999999999999. In that case floor function works correctly and result is 49. (See "jay at w3prodigy dot com" post on 25-Mar-2008 10:01) But this is not that value what i expect. Solution for me is round this value with reasonable precision, for example 10 <?php floor(round($result, 10)); // float(50) // note floor(round($result, 14)); // float(50) floor(round($result, 15)); // float(49) ?> Tested on: PHP/5.2.5 Apache/2.2.3 (Linux/SUSE) PHP/5.1.6 Apache/2.0.59 (Win32) PHP/5.1.6 Apache/2.0.61 (Unix)

« previous php.notes (#151443) next »