F.ture
F.ture

Reputation: 245

Rounding Off numbers in Laravel Blade

<td colspan="3">
    <p class="text-left">
        <h5>Discount ( @php echo "- $subtotalquant"; @endphp  )</h5>
    </p>
</td>
<td>
    <p class="text-right">
        <h5>
            @php
                echo"&#8369;$subtotal";
            @endphp
        </h5>
    </p>
</td>

I wanted to round off the values into two decimal places. But number format doesn't seem to work.

It does look like this ^ enter image description here

$subtotal = 40.608

$subtotalquant = 10.152

Upvotes: 7

Views: 35619

Answers (4)

Julius Fasema
Julius Fasema

Reputation: 902

{{ number_format($subtotal,2) }}
 {{ number_format($subtotalquant,2) }}

Upvotes: 2

Deepak
Deepak

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

Kmg Kumar
Kmg Kumar

Reputation: 616

use like this, and also use the curly braces instead of echo.

{{round($subtotal, 2)}}

Upvotes: 20

Sagar Gautam
Sagar Gautam

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

Related Questions