Issue
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
Solution
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)}}%
Answered By - Mustafa Poya Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.