mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
2db82c2b30
commit
5de968246f
1 changed files with 47 additions and 26 deletions
|
@ -36,7 +36,7 @@
|
|||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
*/
|
||||
class NumberHelper extends Helper{
|
||||
class NumberHelper extends Helper {
|
||||
/**
|
||||
* Formats a number with a level of precision.
|
||||
*
|
||||
|
@ -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 = "€ " . number_format ($number, 2, ",", ".");
|
||||
break;
|
||||
case "GBP":
|
||||
$return = "£" . number_format ($number, 2, ".", ",");
|
||||
break;
|
||||
case 'USD':
|
||||
default:
|
||||
$return = "$" . number_format ($number, 2, ".", ",");
|
||||
break;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Reference in a new issue