Home > php教程 > php手册 > body text

php数字每三位加逗号的功能函数

WBOY
Release: 2016-06-06 19:41:05
Original
1117 people have browsed it

这篇文章主要介绍了php数字每三位加逗号的功能函数,想知道如何做到数字每三位加逗号的朋友可以参考下

php实现数字格式化,数字每三位加逗号的功能函数,具体代码如下:

function num_format($num){ if(!is_numeric($num)){ return false; } $num = explode('.',$num);//把整数和小数分开 $rl = $num[1];//小数部分的值 $j = strlen($num[0]) % 3;//整数有多少位 $sl = substr($num[0], 0, $j);//前面不满三位的数取出来 $sr = substr($num[0], $j);//后面的满三位的数取出来 $i = 0; while($i

另外可以使用系统自带的函数string number_format ( float number [, int decimals [, string dec_point, string thousands_sep]] ):

例子:

echo number_format('169856420');

输出结果将为:169,856,420

echo number_format('1000000',2);

输出结果将为:1,000,000.00

echo number_format('1000000',2,',','.');

输出结果将为:1.000.000,00

以上就是php实现数字每三位加逗号的代码,,刚开始大家看到题目是不是没有思路,小编也是的,希望通过这篇文章可以给大家一些启发。

source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!