note 107643 deleted from function.round by googleguy

From: Date: Sun, 09 Dec 2012 08:13:51 +0000
Subject: note 107643 deleted from function.round by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192407@lists.php.net to get a copy of this message
Note Submitter: qeremy [atta] gmail [dotta] com ---- In order to NOT round up/down the "precision", this function could use; <?php function dont_touch_the_precision($val, $pre = 0) { $val = (string) $val; if (strpos($val, ".") !== false) { $tmp = explode(".", $val); $val = $tmp[0] .".". substr($tmp[1], 0, $pre); } return (float) $val; } echo round(0.164654651, 3); // 0.165 echo "\n"; echo dont_touch_the_precision(0.164654651, 3); // 0.164 ?>

« previous php.notes (#192407) next »