1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * CodeIgniter Number Helpers
21 * @package CodeIgniter
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/helpers/number_helper.html
28 // ------------------------------------------------------------------------
31 * Formats a numbers as bytes, based on size, and adds the appropriate suffix
34 * @param mixed // will be cast as int
37 if ( ! function_exists('byte_format'))
39 function byte_format($num, $precision = 1)
41 $CI =& get_instance();
42 $CI->lang->load('number');
44 if ($num >= 1000000000000)
46 $num = round($num / 1099511627776, $precision);
47 $unit = $CI->lang->line('terabyte_abbr');
49 elseif ($num >= 1000000000)
51 $num = round($num / 1073741824, $precision);
52 $unit = $CI->lang->line('gigabyte_abbr');
54 elseif ($num >= 1000000)
56 $num = round($num / 1048576, $precision);
57 $unit = $CI->lang->line('megabyte_abbr');
61 $num = round($num / 1024, $precision);
62 $unit = $CI->lang->line('kilobyte_abbr');
66 $unit = $CI->lang->line('bytes');
67 return number_format($num).' '.$unit;
70 return number_format($num, $precision).' '.$unit;
75 /* End of file number_helper.php */
76 /* Location: ./system/helpers/number_helper.php */