note 31610 added to function.round
| From: | hlang at systematrix dot net | Date: | Mon, 28 Apr 2003 07:34:13 +0000 |
| Subject: | note 31610 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47191@lists.php.net to get a copy of this message | ||
The following function is good when rounding off prices where for consistancy 2 digits should be
enforced after the comma. It checks whether there are no or just one digit after the comma and adds
"0"s accordingly.
function rounder($in) {
$in = round($in,2);
if (substr($in,-3,1)==".") {$out=$in;} else {
if (!strstr($in,".")) $out = $in.".00";
if (strstr($in,".")) $out = $in."0";}
return $out;
}
--
http://www.php.net/manual/en/function.round.php
http://master.php.net/manage/user-notes.php?action=edit+31610
http://master.php.net/manage/user-notes.php?action=delete+31610
http://master.php.net/manage/user-notes.php?action=reject+31610