note 35263 modified in function.round by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:24:56 +0000 |
| Subject: | note 35263 modified in function.round by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154822@lists.php.net to get a copy of this message | ||
Many have thus far mentioned problems encountered when trying to add a small fuzz factor to a number
such as 1.499999999. This is the way I get around that problem using , allbeit probably less
efficient than assuming a small possiblitiy for error:
<?php
$numberToRound = 1.5;
//Convert to string.
$numberToRound = "$numberToRound";
//iff number ends in a "5", add fuzz
if (eregi("$5", $pages)) $pages += .000001;
$round = round($pages, 0);
?>
--was--
Many have thus far mentioned problems encountered when trying to add a small fuzz factor to a number
such as 1.499999999. This is the way I get around that problem using , allbeit probably less
efficient than assuming a small possiblitiy for error:
$numberToRound = 1.5;
//Convert to string.
$numberToRound = "$numberToRound";
//iff number ends in a "5", add fuzz
if (eregi("$5", $pages)) $pages += .000001;
$round = round($pages, 0);
http://php.net/manual/en/function.round.php