PHP数字格式化

2015-01-24信息快讯网
例如,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
The specified CGI application misbehaved by not returning a complete set of HTTP headers
php下关于Cannot use a scalar value as an array的解决办法
对squid中refresh_pattern的一些理解和建议
php SQL之where语句生成器
php array_intersect()函数使用代码
php strtotime 函数UNIX时间戳
Google PR查询接口checksum新算法第1/2页
PHP setcookie() cannot modify header information 的解决方法
Zend Studio for Eclipse的java.lang.NullPointerException错误的解决方法
php下HTTP Response中的Chunked编码实现方法
PHP syntax error, unexpected $end 错误的一种原因及解决
Zend studio for eclipse中使php可以调用mysql相关函数的设置方法
PHP中str_replace函数使用小结
Cannot modify header information错误解决方法
php utf-8转unicode的函数第1/2页
php出现Cannot modify header information问题的解决方法大全
php Undefined index和Undefined variable的解决方法
Dedecms常用函数解析
动易数据转成dedecms的php程序
手把手教你使用DedeCms V3的在线采集图文教程
dedecms系统常用术语汇总
dedecms模版制作使用方法
echo, print, printf 和 sprintf 区别
用缓存实现静态页面的测试
弄了个检测传输的参数是否为数字的Function
echo(),print(),print_r()之间的区别?
html中select语句读取mysql表中内容
php 中include()与require()的对比
对javascript和select部件的结合运用
利用 window_onload 实现select默认选择
怎样在UNIX系统下安装php3
怎样在UNIX系统下安装MySQL
php的header和asp中的redirect比较
PHP_Flame(Version:Progress)的原代码
用php实现gb2312和unicode间的编码转换
转换中文为unicode 转换unicode到正常文本
新版百元变化更能防伪 收藏越稀缺越值钱
©2014-2024 dbsqp.com