note 107643 added to function.round

From: Date: Thu, 23 Feb 2012 14:38:57 +0000
Subject: note 107643 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-186319@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 69.147.83.197 Probable Submitter: 194.27.149.90 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/107643 Del: integrated -- https://master.php.net/note/delete/107643/integrated Del: useless -- https://master.php.net/note/delete/107643/useless Del: bad code -- https://master.php.net/note/delete/107643/bad+code Del: spam -- https://master.php.net/note/delete/107643/spam Del: non-english -- https://master.php.net/note/delete/107643/non-english Del: in docs -- https://master.php.net/note/delete/107643/in+docs Del: other reasons-- https://master.php.net/note/delete/107643 Reject -- https://master.php.net/note/reject/107643 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186319) next »