PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 10, 2022

[FIXED] How can I show up to 2 decimal points

 August 10, 2022     decimal, laravel, laravel-blade     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing