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

Tuesday, August 9, 2022

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

 August 09, 2022     decimal, laravel, mysql, php     No comments   

Issue

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.


Solution

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.



Answered By - Ahmed Naveed
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