blob: 5a3d72b0069913daa557da4984079f03a29e9ada [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
Derek Jonesc8b742c2013-07-19 16:47:54 -07008.. contents::
9 :local:
10
11.. raw:: html
12
13 <div class="custom-index container"></div>
Derek Jones8ede1a22011-10-05 13:34:52 -050014
15Loading this Helper
16===================
17
Andrey Andreev53b8ef52012-11-08 21:38:53 +020018This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050019
20 $this->load->helper('number');
21
Derek Jonesc8b742c2013-07-19 16:47:54 -070022Available Functions
23===================
24
Derek Jones8ede1a22011-10-05 13:34:52 -050025The following functions are available:
26
Derek Jones8ede1a22011-10-05 13:34:52 -050027
Derek Jonesc8b742c2013-07-19 16:47:54 -070028.. function:: byte_format($num[, $precision = 1])
Derek Jones8ede1a22011-10-05 13:34:52 -050029
Andrey Andreev53b8ef52012-11-08 21:38:53 +020030 :param mixed $num: Number of bytes
31 :param int $precision: Floating point precision
32 :returns: string
33
Derek Jonesc8b742c2013-07-19 16:47:54 -070034 Formats numbers as bytes, based on size, and adds the appropriate
35 suffix. Examples::
Derek Jonesb8c283a2013-07-19 16:02:53 -070036
Derek Jonesc8b742c2013-07-19 16:47:54 -070037 echo byte_format(456); // Returns 456 Bytes
38 echo byte_format(4567); // Returns 4.5 KB
39 echo byte_format(45678); // Returns 44.6 KB
40 echo byte_format(456789); // Returns 447.8 KB
41 echo byte_format(3456789); // Returns 3.3 MB
42 echo byte_format(12345678912345); // Returns 1.8 GB
43 echo byte_format(123456789123456789); // Returns 11,228.3 TB
Derek Jones8ede1a22011-10-05 13:34:52 -050044
Derek Jonesc8b742c2013-07-19 16:47:54 -070045 An optional second parameter allows you to set the precision of the
46 result::
Derek Jones8ede1a22011-10-05 13:34:52 -050047
Derek Jonesc8b742c2013-07-19 16:47:54 -070048 echo byte_format(45678, 2); // Returns 44.61 KB
Derek Jones8ede1a22011-10-05 13:34:52 -050049
Derek Jonesc8b742c2013-07-19 16:47:54 -070050 .. note:: The text generated by this function is found in the following
51 language file: `language/<your_lang>/number_lang.php`