Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ############# |
| 2 | Number Helper |
| 3 | ############# |
| 4 | |
| 5 | The Number Helper file contains functions that help you work with |
| 6 | numeric data. |
| 7 | |
Derek Jones | c8b742c | 2013-07-19 16:47:54 -0700 | [diff] [blame] | 8 | .. contents:: |
| 9 | :local: |
| 10 | |
| 11 | .. raw:: html |
| 12 | |
| 13 | <div class="custom-index container"></div> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 14 | |
| 15 | Loading this Helper |
| 16 | =================== |
| 17 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 18 | This helper is loaded using the following code:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 19 | |
| 20 | $this->load->helper('number'); |
| 21 | |
Derek Jones | c8b742c | 2013-07-19 16:47:54 -0700 | [diff] [blame] | 22 | Available Functions |
| 23 | =================== |
| 24 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 25 | The following functions are available: |
| 26 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 27 | |
Derek Jones | c8b742c | 2013-07-19 16:47:54 -0700 | [diff] [blame] | 28 | .. function:: byte_format($num[, $precision = 1]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 29 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 30 | :param mixed $num: Number of bytes |
| 31 | :param int $precision: Floating point precision |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 32 | :returns: Formatted data size string |
| 33 | :rtype: string |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 34 | |
Derek Jones | c8b742c | 2013-07-19 16:47:54 -0700 | [diff] [blame] | 35 | Formats numbers as bytes, based on size, and adds the appropriate |
| 36 | suffix. Examples:: |
Derek Jones | b8c283a | 2013-07-19 16:02:53 -0700 | [diff] [blame] | 37 | |
Derek Jones | c8b742c | 2013-07-19 16:47:54 -0700 | [diff] [blame] | 38 | echo byte_format(456); // Returns 456 Bytes |
| 39 | echo byte_format(4567); // Returns 4.5 KB |
| 40 | echo byte_format(45678); // Returns 44.6 KB |
| 41 | echo byte_format(456789); // Returns 447.8 KB |
| 42 | echo byte_format(3456789); // Returns 3.3 MB |
| 43 | echo byte_format(12345678912345); // Returns 1.8 GB |
| 44 | echo byte_format(123456789123456789); // Returns 11,228.3 TB |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 45 | |
Derek Jones | c8b742c | 2013-07-19 16:47:54 -0700 | [diff] [blame] | 46 | An optional second parameter allows you to set the precision of the |
| 47 | result:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 48 | |
Derek Jones | c8b742c | 2013-07-19 16:47:54 -0700 | [diff] [blame] | 49 | echo byte_format(45678, 2); // Returns 44.61 KB |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 50 | |
Derek Jones | c8b742c | 2013-07-19 16:47:54 -0700 | [diff] [blame] | 51 | .. note:: The text generated by this function is found in the following |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 52 | language file: *language/<your_lang>/number_lang.php* |