<p>JS保留两位小数例子 四舍五入使用函数 toFixed()</p><pre class="brush:html;toolbar:false"><html>
<head>
</head>
<scriptlanguage="javascript">
document.write("<h1>JS保留两位小数例子</h1><br>");
vara=2.1512131231231321;
document.write("原来的值:"+a+"<br>");
document.write("两位小数点:"+a.toFixed(2)+"<br>四位小数点"+a.toFixed(4));
</script>
<body>
</body>
</html></pre><p>PHP保留两位小数例子 四舍五入</p><pre class="brush:php;toolbar:false"><?php
/**1.number_format*/
$number=1234.5678;
$nombre_format_francais=number_format($number,2,',','');//1234,57
$english_format_number=number_format($number,2,'.','');//1234.57(我一般用这个)
/**2.round*/
$number=1234.5678;
echoround($number,2);//1234.57
/**3.sprintf*/
$formatted=sprintf("%s有¥%01.2f。",$name,$money);
echo$formatted;//张三有¥123.10。
?></pre>