我對php的數學對象有一個小小的困難。 每當我回顯總數時,它將顯示2位小數,除非數字爲.00,否則不會。 所以20.00 - 10.00會顯示10,而20.00 - 9.99會顯示10.01簡單的php數學對象(ABS方法) - 得到2位小數
我想總是顯示2位小數。
當我搜索互聯網時,我無法找到將其添加到我的代碼的方式。我認爲應該用'number_format($ total_sub,2)'來完成,但是怎麼做?
請參閱解析結束編號示例代碼:
<?php
$less_subtotal= '10.00';
$order_subtotal= '20.00';
$total_sub = abs($order_subtotal - $less_subtotal);
number_format($total_sub, 2);// output is still witouth 2 decimals...
echo $total_sub;
?>
---編輯--- 跟我描述了貼我知道這個問題.... EPIC ..
echo number_format($total_sub, 2);
現在應該沒問題了嗎?