企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 数字辅助函数 数字辅助函数文件包含了用于处理数字的一些函数。 [TOC=2,3] ## [加载辅助函数](http://codeigniter.org.cn/user_guide/helpers/number_helper.html#id4) 该辅助函数通过下面的代码加载: ~~~ $this->load->helper('number'); ~~~ ## [可用函数](http://codeigniter.org.cn/user_guide/helpers/number_helper.html#id5) 该辅助函数有下列可用函数: byte_format($num[, $precision = 1]) 参数: * **$num** (mixed) -- Number of bytes * **$precision** (int) -- Floating point precision 返回: Formatted data size string 返回类型: string 根据数值大小以字节的形式格式化,并添加适合的缩写单位。 譬如: ~~~ 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 ~~~ 可选的第二个参数允许你设置结果的精度: ~~~ echo byte_format(45678, 2); // Returns 44.61 KB ~~~ 注解 这个函数生成的缩写单位可以在 language//number_lang.php 语言文件中找到。