-2

I am making a ecommerce website in laravel 6.20 and in the product view page I wanted to show the discount at a percantage rate. I could show a round figure but I want to show the percentage at a 2 decimal point format. any help will be appreciated.

<ul class="product_marks">
    @if($row->discount_price == NULL)
    @else
       <li class="product_mark product_discount">
       -{{round(($row->discount_price/$row->selling_price)*100)}}%
       </li>
    @endif
    <li class="product_mark product_new">NEW</li>
</ul>

Please check this image for reference

Masudalimran
  • 133
  • 2
  • 11
  • 1
    Could you tag your question with the languages/libraries you are using. It would help people who know the correct environment come to your question. – A Haworth Nov 09 '20 at 13:17
  • 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) – P. K. Tharindu Nov 09 '20 at 14:20

1 Answers1

3

you can use number_format($number, $decimal_points) to define number of decimal points you want:

-{{number_format(round(($row->discount_price/$row->selling_price)*100), 2)}}%
Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36