Ravi Ravi - 7 months ago 35
SQL Question

HTML Not showing decimals from mysql db in Laravel Blade

In my mysql db I manage table's column to keep product prices.like $200.00 or $200.50 (only two points). When it comes to html I catch it like this from blade view.

<p class="excerpt col-md-6 col-md-offset-5 alert alert-danger">Price per Instance : AUD ${{$product->product_price}}</p>


Problem is, $200.00 it is not showing .00 and when $200.50 it is 200.5 and $200.51 or any two point it gives $200.50999450684 something like this. What should I do

And also please let me know how to save number with two decimal point in html to mysql db

Thanks....

Update 01:
my table structure

enter image description here

Answer

Make sure to set your produce price column in MySQL to DECIMAL(5,2) for prices between $0 to $999.99. If it's not, run

ALTER TABLE #PRODUCTTABLENAME MODIFY COLUMN #PRODUCTPRICECOLUMNNAME DECIMAL(5,2)

replacing #PRODUCTTABLENAME with your table's name and #PRODUCTPRICECOLUMNNAME with your column's name

Comments