教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php格式化数字的小例子 number_format函数的用法举例

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

发布时间:2017-02-21   编辑:jiaochengji.com
本文介绍下,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);
?>

您可能感兴趣的文章:
php格式化数字的小例子 number_format函数的用法举例
PHP 数字格式化函数number_format的用法
php number_format()保留小数点后几位
php 数字格式化函数 number_format 简介
php数字格式化的例子(number_format函数应用)
php number_format函数怎么用?
PHP小数点后保留几位的简单示例
php 格式化数字 位数不足前面加0补足的实现方法
php保留两位小数的方法
学习php的number_format() 函数定义和用法

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