php 保留小数和 js 四舍五入函数 toFixed 的用法:
<html>
<head> </head>
<script type="text/javascript">
document.write("<h1>php 保留小数和 js 四舍五入函数 toFixed 的用法 -php 自学网 </h1><br>");
var a=2.1512131231231321;
document.write(" 原来的值:"+a+"<br>");
document.write(" 两位小数点:"+a.toFixed(2)+"<br> 四位小数点 "+a.toFixed(4));
</script>
<body>
</body>
</html>
php 保留两位小数例子 – 四舍五入
1.number_format
$number = 1234.5678;
$nombre_format_francais = number_format($number, 2, ',', ' '); // 1 234,57
$english_format_number = number_format($number, 2, '.', ''); // 1234.57
2.round
$number = 1234.5678; echo round($number ,2); //1234.57
3.sprintf
$formatted = sprintf ("%s 有¥%01.2f。",$name, $money);
echo $formatted; // 张三有¥123.10。
正文完
发表至: 建站源码
2015-02-09