note 78314 modified in function.number-format by levim
| From: | levim@php.net | Date: | Mon, 24 Feb 2014 23:07:01 +0000 |
| Subject: | note 78314 modified in function.number-format by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198700@lists.php.net to get a copy of this message | ||
A simple funtion to format american dollars.
<?php
function formatMoney($money) {
if($money<1) {
$money='¢'.$money*100;
}
else {
$dollars=intval($money);
$cents=$money-$dollars;
$cents=$cents*100;
$money='$'.$dollars.' and ¢'.$cents;
}
return $money;
}
echo formatmoney('52.342');
?>
This will output: " $52 and ¢34.2 ".
--was--
A simple funtion to format american dollars.
<?
function formatMoney($money) {
if($money<1) {
$money='¢'.$money*100;
}
else {
$dollars=intval($money);
$cents=$money-$dollars;
$cents=$cents*100;
$money='$'.$dollars.' and ¢'.$cents;
}
return $money;
}
echo formatmoney('52.342');
?>
This will output: " $52 and ¢34.2 ".
http://php.net/manual/en/function.number-format.php