Reputation: 245
<td colspan="3">
<p class="text-left">
<h5>Discount ( @php echo "- $subtotalquant"; @endphp )</h5>
</p>
</td>
<td>
<p class="text-right">
<h5>
@php
echo"₱$subtotal";
@endphp
</h5>
</p>
</td>
I wanted to round off the values into two decimal places. But number format doesn't seem to work.
$subtotal = 40.608
$subtotalquant = 10.152
Upvotes: 7
Views: 35619
Reputation: 902
{{ number_format($subtotal,2) }}
{{ number_format($subtotalquant,2) }}
Upvotes: 2
Reputation: 36
If you want to implement this code in a blade file then use it like this:
{{number_format((float)$subtotal, 2, '.', '')}}
{{number_format((float)$subtotalquant, 2, '.', '')}}
Same thing if you want it in a PHP file then please follow the sagar's code.
Upvotes: 0
Reputation: 616
use like this, and also use the curly braces instead of echo.
{{round($subtotal, 2)}}
Upvotes: 20
Reputation: 9389
Use Number format like this:
echo number_format((float)$subtotal, 2, '.', '');
echo number_format((float)$subtotalquant, 2, '.', '');
For more details you can see docs over here: https://www.php.net/manual/en/function.number-format.php
Upvotes: 12