note 76846 added to function.strrchr
| From: | subbz2k at yahoo dot de | Date: | Wed, 01 Aug 2007 23:32:34 +0000 |
| Subject: | note 76846 added to function.strrchr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129117@lists.php.net to get a copy of this message | ||
i just recently did a function, that uses strrchr to format - let's say a currency - with 2
decimals. can also be done using number_format but you may NOT always want an automatic rounding of
your decimals. thats there this function comes in handy:
<?php
function formatTwoDecimals($value, $trim)
{
$after_comma = substr(strrchr($value, $trim), 0, 3);
$in_front_of_comma = (int) $value;
$final = $in_front_of_comma . $after_comma;
return $final;
}
echo formatTwoDecimals("365.6078985", ".");
?>
this will produce
365.60
instead of
365.61
which will show up then you use number_format.
----
Server IP: 69.147.83.197
Probable Submitter: 91.40.110.90
----
Manual Page -- http://www.php.net/manual/en/function.strrchr.php
Edit -- https://master.php.net/note/edit/76846
Del: integrated -- https://master.php.net/note/delete/76846/integrated
Del: useless -- https://master.php.net/note/delete/76846/useless
Del: bad code -- https://master.php.net/note/delete/76846/bad+code
Del: spam -- https://master.php.net/note/delete/76846/spam
Del: non-english -- https://master.php.net/note/delete/76846/non-english
Del: in docs -- https://master.php.net/note/delete/76846/in+docs
Del: other reasons-- https://master.php.net/note/delete/76846
Reject -- https://master.php.net/note/reject/76846
Search -- https://master.php.net/manage/user-notes.php