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 | |
| 8 | .. contents:: Page Contents |
| 9 | |
| 10 | Loading this Helper |
| 11 | =================== |
| 12 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame^] | 13 | This helper is loaded using the following code:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 14 | |
| 15 | $this->load->helper('number'); |
| 16 | |
| 17 | The following functions are available: |
| 18 | |
| 19 | byte_format() |
| 20 | ============= |
| 21 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame^] | 22 | .. php:function:: byte_format($num, $precision = 1) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 23 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame^] | 24 | :param mixed $num: Number of bytes |
| 25 | :param int $precision: Floating point precision |
| 26 | :returns: string |
| 27 | |
| 28 | Formats numbers as bytes, based on size, and adds the appropriate |
| 29 | suffix. Examples:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 30 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame^] | 31 | echo byte_format(456); // Returns 456 Bytes |
| 32 | echo byte_format(4567); // Returns 4.5 KB |
| 33 | echo byte_format(45678); // Returns 44.6 KB |
| 34 | echo byte_format(456789); // Returns 447.8 KB |
| 35 | echo byte_format(3456789); // Returns 3.3 MB |
| 36 | echo byte_format(12345678912345); // Returns 1.8 GB |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 37 | echo byte_format(123456789123456789); // Returns 11,228.3 TB |
| 38 | |
| 39 | An optional second parameter allows you to set the precision of the |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame^] | 40 | result:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 41 | |
| 42 | echo byte_format(45678, 2); // Returns 44.61 KB |
| 43 | |
| 44 | .. note:: The text generated by this function is found in the following |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame^] | 45 | language file: `language/<your_lang>/number_lang.php` |