Legacy Documentation
You are using the documentation for version 3.5.17. Go here for the latest version or check here for your available upgrades to the latest version.
Number Helper¶
The Number Helper file contains functions that help you work with numeric data. This helper is loaded using the following code:
ee()->load->helper('number');
Available Functions¶
-
byte_format
($num[, $precision = 1])¶ Parameters: - $num (mixed) – Number of bytes
- $precision (int) – Floating point precision
Returns: Formatted data size string
Return type: string
Formats numbers as bytes, based on size, and adds the appropriate suffix. Examples:
echo byte_format(456); // Returns 456 Bytes echo byte_format(4567); // Returns 4.5 KB echo byte_format(45678); // Returns 44.6 KB echo byte_format(456789); // Returns 447.8 KB echo byte_format(3456789); // Returns 3.3 MB echo byte_format(12345678912345); // Returns 1.8 GB echo byte_format(123456789123456789); // Returns 11,228.3 TB
An optional second parameter allows you to set the precision of the result:
echo byte_format(45678, 2); // Returns 44.61 KB
Note
The text generated by this function is found in the following language file: language/<your_lang>/number_lang.php
-
get_bytes
($setting)¶ Parse INI style size into bytes
Parameters: - $setting (string) – INI formatted size
Returns: Size in bytes
Rytpe: int