number_format
number_format — 以千位分隔符方式格式化一个数字
说明
$number [, int $decimals = 0 ] )$number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," )本函数可以接受1个、2个或者4个参数(注意:不能是3个):
如果只提供第一个参数,number的小数部分会被去掉 并且每个千位分隔符都是英文小写逗号","
如果提供两个参数,number将保留小数点后的位数到你设定的值,其余同楼上
如果提供了四个参数,number 将保留decimals个长度的小数部分, 小数点被替换为dec_point,千位分隔符替换为thousands_sep
参数
number-
你要格式化的数字
decimals-
要保留的小数位数
dec_point-
指定小数点显示的字符
thousands_sep-
指定千位分隔符显示的字符
返回值
格式化以后的 number.
<?php $number = 1234.56; // english notation (default)
$english_format_number = number_format($number);
// 1,235 // French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56 $number = 1234.5678; // english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57 ?>
number_format的更多相关文章
- js 实现类似php函数number_format的功能
今天同事在做一个功能的时候需要使用js来实现类似php函数number_format的功能,最后就有了下面的方法,可以实现了: /** * number_format * @param number ...
- 与number_format函数有关的一个bug?
最近在做一个模仿excel功能的在线项目.其中有一个功能,数据列表中的数据,到了最后一列都要进行总计.这本来没什么难度.直接从数据库取出数据后,进行foreach相加就行 了.这是如此的简单,以至于用 ...
- number_format函数的使用
<!-- ###:表示传入的价格,2:保留两位小数,'.':用点区分, --> <!-- 该函数只支持1.2.4个参数.不能只写3个参数 --> <span>< ...
- php number_format()保留小数点后几位
[PHP_保留两位小数的相关函数] php保留两位小数并且四舍五入 Php代码 1 $num = 123213.666666; 2 echo sprintf("%.2f ...
- Js 和 PHP 中保留小数点后X位数的方法 toFixed、round、number_format、sprintf
在 Javacript 中保留小数点后两位数的方法为 toFixed(2),其中的2为保留两位,写多少就保留多少了,满5进1. Javacript例子: var num = 24.54789523; ...
- php number_format()保留小数点后几位有效数的函数 千位分组来格式化数字(转)
PHP保留小数点后2位的函数number_format number_format(带小数点的书,小数点后保留的位数) number_format(8.3486,2); //取得小数点后2位有效数/ ...
- [PHP源码阅读]number_format函数
上次讲到PHP是如何解析大整数的,一笔带过了number_format的处理,再详细阅读该函数的源码,以下是小分析. 函数原型 string number_format ( float $number ...
- php格式化数字输出number_format
<?php $num = 4999.944444; $formattedNum = number_format($num).PHP_EOL; echo $formattedNum; $forma ...
- PHP 浮点数 转化 整数方法对比 ceil,floor,round,intval,number_format
ceil,floor,round,intval,number_format - 执行1000W此效率对比 Header("Content-Type:text/html;charset=utf ...
随机推荐
- 远程mysql服务器无法连接解决方案
错误现象:Habon被拒绝. 远程服务器无法连接从两个方面看 1.是否能ping通远程服务器 windows下查看防火墙是否已关闭 linux下查看iptables等 2.数据库是否有开用户管理权限 ...
- MOPSO 多目标例子群优化算法
近年来,基于启发式的多目标优化技术得到了很大的发展,研究表明该技术比经典方法更实用和高效.有代表性的多目标优化算法主要有NSGA.NSGA-II.SPEA.SPEA2.PAES和PESA等.粒子群优化 ...
- MyEclipse 死掉,JVM terminated. Exit code=1073807364
刚入手的新成员,刚开始使用myeclipse,是不是会有一大堆的问题,然后没有目标的走,这里有个小技巧,那就是如果做项目出现问题,一定要自己现在网络搜寻答案,网络时代.技术时代走到现在,一定有他的道理 ...
- beta阶段事后诸葛亮会议
项目名:约跑 组名:nice! 组长:李权 组员: 韩媛媛 于淼 刘芳芳 宫丽君 Beta Review会议 时间:2016.11.15 地点:冬华楼一楼大厅 会议内容: 约跑APP的Beta Rev ...
- [CrunchBang]中文字体美化
安装必要的字体包 sudo apt-get install ttf-droid ttf-wqy-zenhei xfonts-wqy ttf-wqy-microhei ttf-arphic-ukai t ...
- imread函数、namedWindow函数、imshow函数、imwrite函数
1.imread函数 首先,我们看imread函数,可以在OpenCV官方文档中查到其原型如下: Mat imread(const string& filename, int flags=1 ...
- 用smack+openfire做即时通讯
首发:个人博客 必须说明:smack最新的4.1.1,相对之前版本变化很大,而且资料缺乏,官方文档也不好,所以还是用老版本3.2.2吧.这篇博文中的代码是4.1.1版的,但不推荐用它.用openfir ...
- umask setuid setgid
cat /etc/bashrc if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ];#用户UI ...
- 使用git和github托管个人项目
1. 安装 cygwin 和 cygwin 下的 git , 测试 git 命令可用; 参考: https://cygwin.com/install.html 2. 注册 github 账号: ...
- html插入视频
http://www.jb51.net/web/168548.html http://www.w3school.com.cn/html/html_media.asp