-2

I have this. Its made in laravel

public function render()
{

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

And also this:

            <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>

And it show the result like 33.333333333333% How can I round to just 2 decimals? Thanks

Omar GB
  • 29
  • 6
  • 1
    Does this answer your question? [Show a number to two decimal places](https://stackoverflow.com/questions/4483540/show-a-number-to-two-decimal-places) – Andrew Mar 02 '22 at 22:48
  • Does this answer your question? [number format in php 999.99](https://stackoverflow.com/questions/14701077/number-format-in-php-999-99) – gguney Mar 03 '22 at 04:53

2 Answers2

2

Its PHP round() function.

So you wanna use:

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

It is basically round($number,$decimal_places)

Aleksandar Đokić
  • 2,118
  • 17
  • 35
1

Simple php function:

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

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

jeremykenedy
  • 4,150
  • 1
  • 17
  • 25