laravel如何四舍五入到2位小数?

How can round to 2 decimals in laravel?

我有这个。它是在 laravel

制作的
public function render()
{

    $percentageNotAnswered = ($noanswer * 100) / $mytickets;

还有这个:

            <span class="text-2xl font-semibold text-gray-700"> {{ $noanswer ?? "" }} </span>
            <span class="text-sm  text-gray-500">  {{ $percentageNotAnswered ?? '' }}% </span>

            <div class="text-gray-500">Tickets with no Answer</div>
         </div>

结果显示为 33.333333333333% 我怎样才能四舍五入到两位小数? 谢谢

简单php函数:

round(($noanswer * 100) / $mytickets, 2);

https://www.php.net/manual/en/function.round.php

它的 PHP round() 函数。

所以你想使用:

$percentageNotAnswered = round(($noanswer * 100) / $mytickets), 2);

基本上是round($number,$decimal_places)