Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php格式化数字的小例子 number_format函数的用法举例

php格式化数字的小例子 number_format函数的用法举例

发布时间:2017-02-21   编辑:www.jquerycn.cn
本文介绍下,php中用于格式化数字的函数number_format的用法,举了几个小例子,供大家学习参考。

例1,格式化数字为文本
 

复制代码 代码示例:
<?php
print number_format(100000.56 );
?>

例2,number_format($n, $p, $t, $d) rounds $n to $p decimal places, using $t as the thousands separator and $d as the decimal separator.
 

复制代码 代码示例:
<?
    echo "Total charge is ", number_format($total, 2, ".", ","), " Euros";
?>

例3,number_format函数用于English format and Italian format
 

复制代码 代码示例:

<?php
    $a = 1232322210.44;
    echo number_format ($a, 2);   // English format
    echo "\n";
    echo number_format ($a, 2, ',', '.'); // Italian format
    echo "\n";
?>

例4,输出格式化的数字形式
 

复制代码 代码示例:
<?php
print "The population of the US is about:";
print number_format(285266237);
?>

您可能感兴趣的文章:

关键词: number_format  数字格式化   
[关闭]