Home >php教程 >php手册 >数字格式化

数字格式化

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-22 18:36:05838browse

之前曾经一直使用自己定义的数字格式化方法,原来PHP一直有个数字格式化函数的,呵呵~

例如,echo number_format(285266237);

可以输出 285,266,237

另外假如需要格式化文件字节大小,下面的方法可以借鉴:

<?php
function byte_format($input, $dec = 0) {
    $prefix_arr = array(
        " B",
        "K",
        "M",
        "G",
        "T"
    );
    $value = round($input, $dec);
    $i = 0;
    while ($value > 1024) {
        $value/= 1024;
        $i;
    }
    $return_str = round($value, $dec) . $prefix_arr[$i];
    return $return_str;
}
echo byte_format(285266237);

显示结果为272M


教程网址:

欢迎收藏∩_∩但请保留本文链接。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn