CodeIgniter 使用手冊版本 2.1.4


Number 輔助函數

數字輔助函數檔案包含幫助您處理數字資料。

載入 輔助函數

使用下列的程式碼載入補助程式:

$this->load->helper('number');

下列為可以使用的函數:

byte_format()

將文件容量大小以位元組(bytes)為單位格式化,並加上適合的對應縮寫單位。例如:

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

注意: 這函數產生的單位名稱,可以在此語言檔案找到: language//number_lang.php