Reputation: 81
I can do this using printf()
printf ("Total amount of order is %.2f", $total);
Can I do the same using echo, or I have to use printf()?
Upvotes: 0
Views: 72
Reputation: 5309
You can use this..
$total= 100.123;
echo "Total amount of order is ". round($total, 2);
Output:
Total amount of order is 100.12
Upvotes: -1
Reputation: 111839
You cannot specify format using echo.
However if you need to assign result to string, you can simple use sprintf
function:
$var = sprintf ("Total amount of order is %.2f", $total);
echo $var;
Upvotes: 0
Reputation: 2528
Using echo alone? No. You would include number_format
in the echoed string for the same functionality.
echo "Total amount of order is ".number_format($total,2);
Upvotes: 4