Reputation: 401
How to make auto convert a decimal data type into number not a string in php?
I changed data field into decimal(4,2) from double. I have many checks like
if ($row->field)
And $row->field === 0.00. When it was double it's ok. But when I get decimal in php it's get string type and '0.00' it's TRUE.
"Add (float) before $row->field" are not my way, because I change many field and too many places where I use it.
I want find a better way, than change too many lines of code. Maybe some extensions or something else.
Upvotes: 1
Views: 234
Reputation: 1630
Why not return a boolean expression from MySQL itself as part of your query?
SELECT decimal_column <> 0.00 as bool_expression FROM table;
Then test the expression like: if($row->bool_expression)
Upvotes: 1