Fixing NumberHelper code formatting, and adding currency() method (Ticket #853)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3124 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-06-17 03:19:43 +00:00
parent 2db82c2b30
commit 5de968246f

View file

@ -57,24 +57,21 @@ class NumberHelper extends Helper{
* @static
*/
function toReadableSize($size) {
switch($size)
{
case 1: return '1 Byte';
case $size < 1024: return $size . ' Bytes';
case $size < 1024 * 1024: return NumberHelper::precision($size / 1024, 0) . ' KB';
case $size < 1024 * 1024 * 1024: return NumberHelper::precision($size / 1024 / 1024, 2) . ' MB';
switch($size) {
case 1:
return '1 Byte';
case $size < 1024:
return $size . ' Bytes';
case $size < 1024 * 1024:
return NumberHelper::precision($size / 1024, 0) . ' KB';
case $size < 1024 * 1024 * 1024:
return NumberHelper::precision($size / 1024 / 1024, 2) . ' MB';
case $size < 1024 * 1024 * 1024 * 1024:
return NumberHelper::precision($size / 1024 / 1024 / 1024, 2) . ' GB';
case $size < 1024 * 1024 * 1024 * 1024 * 1024:
return NumberHelper::precision($size / 1024 / 1024 / 1024 / 1024, 2) . ' TB';
}
}
/**
* Formats a number into a percentage string.
*
@ -86,5 +83,29 @@ class NumberHelper extends Helper{
function toPercentage($number, $precision = 2) {
return NumberHelper::precision($number, $precision) . '%';
}
/**
* Formats a number into a percentage string.
*
* @param float $number A floating point number
* @param integer $precision The precision of the returned number
* @return string Percentage string
* @static
*/
function currency ($number, $currency = 'USD') {
switch ($currency) {
case "EUR":
$return = "&#128; " . number_format ($number, 2, ",", ".");
break;
case "GBP":
$return = "&#163;" . number_format ($number, 2, ".", ",");
break;
case 'USD':
default:
$return = "$" . number_format ($number, 2, ".", ",");
break;
}
return $return;
}
}
?>