/usr/share/php/Horde/View/Helper/Number.php is in php-horde-view 2.0.6-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <?php
/**
* Copyright 2007 Maintainable Software, LLC
* Copyright 2006-2016 Horde LLC (http://www.horde.org/)
*
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
* @author Chuck Hagenbuch <chuck@horde.org>
* @license http://www.horde.org/licenses/bsd
* @category Horde
* @package View
* @subpackage Helper
*/
/**
* View helpers for numbers.
*
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
* @author Chuck Hagenbuch <chuck@horde.org>
* @license http://www.horde.org/licenses/bsd
* @category Horde
* @package View
* @subpackage Helper
*/
class Horde_View_Helper_Number extends Horde_View_Helper_Base
{
/**
* Formats the bytes in $size into a more understandable representation.
*
* Useful for reporting file sizes to users. This method returns NULL if
* $size cannot be converted into a number. You can change the default
* precision of 1 in $precision.
*
* <pre>
* $this->numberToHumanSize(123) => 123 Bytes
* $this->numberToHumanSize(1234) => 1.2 KB
* $this->numberToHumanSize(12345) => 12.1 KB
* $this->numberToHumanSize(1234567) => 1.2 MB
* $this->numberToHumanSize(1234567890) => 1.1 GB
* $this->numberToHumanSize(1234567890123) => 1.1 TB
* $this->numberToHumanSize(1234567, 2) => 1.18 MB
* </pre>
*
* @param integer|float $size Size to format.
* @param integer $preceision Level of precision.
*
* @return string Formatted size value.
*/
public function numberToHumanSize($size, $precision = 1)
{
if (!is_numeric($size)) {
return null;
}
if ($size == 1) {
$size = '1 Byte';
} elseif ($size < 1024) {
$size = sprintf('%d Bytes', $size);
} elseif ($size < 1048576) {
$size = sprintf("%.{$precision}f KB", $size / 1024);
} elseif ($size < 1073741824) {
$size = sprintf("%.{$precision}f MB", $size / 1048576);
} elseif ($size < 1099511627776) {
$size = sprintf("%.{$precision}f GB", $size / 1073741824);
} else {
$size = sprintf("%.{$precision}f TB", $size / 1099511627776);
}
return str_replace('.0', '', $size);
}
}
|