blob: 8e0ebda5ef105923faf6062b8f5e261bd11e747c [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001#############
2Number Helper
3#############
4
5The Number Helper file contains functions that help you work with
6numeric data.
7
8.. contents:: Page Contents
9
10Loading this Helper
11===================
12
Andrey Andreev53b8ef52012-11-08 21:38:53 +020013This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050014
15 $this->load->helper('number');
16
17The following functions are available:
18
19byte_format()
20=============
21
Andrey Andreev53b8ef52012-11-08 21:38:53 +020022.. php:function:: byte_format($num, $precision = 1)
Derek Jones8ede1a22011-10-05 13:34:52 -050023
Andrey Andreev53b8ef52012-11-08 21:38:53 +020024 :param mixed $num: Number of bytes
25 :param int $precision: Floating point precision
26 :returns: string
27
28Formats numbers as bytes, based on size, and adds the appropriate
29suffix. Examples::
Derek Jones8ede1a22011-10-05 13:34:52 -050030
Andrey Andreev53b8ef52012-11-08 21:38:53 +020031 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 Jones8ede1a22011-10-05 13:34:52 -050037 echo byte_format(123456789123456789); // Returns 11,228.3 TB
38
39An optional second parameter allows you to set the precision of the
Andrey Andreev53b8ef52012-11-08 21:38:53 +020040result::
Derek Jones8ede1a22011-10-05 13:34:52 -050041
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 Andreev53b8ef52012-11-08 21:38:53 +020045 language file: `language/<your_lang>/number_lang.php`