2014-07-16 25 views

回答

-1

你可以使用這個..

$total= 100.123; 
echo "Total amount of order is ". round($total, 2); 

輸出

Total amount of order is 100.12 
+0

不錯又短!非常感謝next2u! –

+0

如果總數達到一個整數,它將不輸出到2個小數位。輪(120.00,2)= 120,而不是120.00。單個數字相同,120.20將變爲120.2。 –

+0

@JamesHunt,你是對的..謝謝 – next2u

4

單獨使用回聲?不可以。您將在回顯字符串中包含number_format以獲得相同的功能。

echo "Total amount of order is ".number_format($total,2); 
+0

這就是我想要的。謝謝詹姆斯! –

0

您不能使用echo指定格式。

但是如果你需要結果分配給字符串,可以簡單的使用功能sprintf

$var = sprintf ("Total amount of order is %.2f", $total); 
echo $var; 
+0

哦,我也可以使用sprintf()。謝謝Marcin! –

相關問題