Laravel Blade 中的四舍五入数字

F.t*_*ure 2 php laravel laravel-5.4

<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>
Run Code Online (Sandbox Code Playgroud)

我想将这些值四舍五入到小数点后两位。但是数字格式似乎不起作用。

它看起来像这样^ 在此处输入图片说明

$subtotal = 40.608

$subtotalquant = 10.152
Run Code Online (Sandbox Code Playgroud)

小智 8

像这样使用,并且还使用花括号代替 echo。

{{round($subtotal, 2)}}
Run Code Online (Sandbox Code Playgroud)


Sag*_*tam 6

像这样使用数字格式:

echo number_format((float)$subtotal, 2, '.', '');

echo number_format((float)$subtotalquant, 2, '.', '');
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,您可以在此处查看文档:https : //www.php.net/manual/en/function.number-format.php