Ahmed Naveed
Ahmed Naveed

Reputation: 104

Why a decimal value from MySQL is converted into/shown as integer?

My database includes a table named Quotations. This table has a column named Cost with a datatype decimal (10, 2). Values are saved/updated as per my expectation inside the column just like (25.75, 4.35, 10.38 etc).

Problem is that whenever I use {{ $quotation->cost }} to display the information, all the decimals are printed as integers like (25, 4, 10). But if I check it with {{ dd($quotation) }}, it shows all the exact decimal values like (25.75, 4.35, 10.38 etc).

I shall appreciate it if someone points out the root cause of the problem.

Upvotes: 0

Views: 939

Answers (3)

Ahmed Naveed
Ahmed Naveed

Reputation: 104

Problem solved. I thank everybody for your timely responses.

Before the solution, I actually was ignoring protected $casts = [ 'cost' => 'integer' ]. Replacing integer to float resolved my issue.

Upvotes: 1

Muzaffar Shaikh
Muzaffar Shaikh

Reputation: 642

Use number_format function while displaying the decimal value

Upvotes: 0

Bishwajeet Kumar
Bishwajeet Kumar

Reputation: 11

Use {!! $quotation->cost !!}

Upvotes: 0

Related Questions