blob: 9d5e98cfb5e54dd95325f894a63bbfefcd023b1e [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
Andrey Andreevcd3d9db2015-02-02 13:41:01 +020028.. php: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
Andrey Andreev3de130c2014-02-07 23:31:49 +020032 :returns: Formatted data size string
33 :rtype: string
Andrey Andreev53b8ef52012-11-08 21:38:53 +020034
Derek Jonesc8b742c2013-07-19 16:47:54 -070035 Formats numbers as bytes, based on size, and adds the appropriate
36 suffix. Examples::
Derek Jonesb8c283a2013-07-19 16:02:53 -070037
Derek Jonesc8b742c2013-07-19 16:47:54 -070038 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 Jones8ede1a22011-10-05 13:34:52 -050045
Derek Jonesc8b742c2013-07-19 16:47:54 -070046 An optional second parameter allows you to set the precision of the
47 result::
Derek Jones8ede1a22011-10-05 13:34:52 -050048
Derek Jonesc8b742c2013-07-19 16:47:54 -070049 echo byte_format(45678, 2); // Returns 44.61 KB
Derek Jones8ede1a22011-10-05 13:34:52 -050050
Derek Jonesc8b742c2013-07-19 16:47:54 -070051 .. note:: The text generated by this function is found in the following
Andrey Andreev3de130c2014-02-07 23:31:49 +020052 language file: *language/<your_lang>/number_lang.php*