简体   繁体   中英

How to automatically convert decimal into number not a string in php?

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM