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

PHP数字格式化

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:35:35
Original
1128 people have browsed it

例如,echo number_format(285266237);  

可以输出 285,266,237  

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

 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  

例如,echo number_format(285266237);  
可以输出 285,266,237  
另外如果需要格式化文件字节大小,下面的方法可以借鉴:  
 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

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template