在报价的时候为了给浏览者更清晰明确的数字,所以需要用到数字格式化,有两种方法,一种自己写函数,另一种当然是系统自带的,其实我更喜欢系统自带的。
先来系统简单的:
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
再看写的函数:
01 |
function num_format( $num ){ |
03 |
if (! is_numeric ( $num ))
{ |
07 |
$num = explode ( "." , $num ); |
09 |
$j = strlen ( $num [0])
% 3; |
10 |
$sl = substr ( $num [0],
0, $j ); |
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。