php 数字格式化
2019-07-10 本文已影响0人
observerb
1.位数不足前面补0
for($i=1; $i<=17 ;$i++){
$var = sprintf("0%3d",$i);
echo $var ."<br />";
}
结果:001 ,002,003,004.....017
2.格式数字 number_format
<?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 seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
?>