MYSQL change float field to decimal

Asked

Viewed 35 times

0

My queries using PHP PDO in Mysql FLOAT fields do not find results with cents.
It seems to me that PHP PDO always sends the value of the variable as a string. Even with the variable typed in float.

That’s why when I run PHP PDO:
WHERE total = '32.00' -> got results
WHERE total = '32.90' -> got no results

Running the query directly in the database
WHERE total = 32.00 -> got results
WHERE total = 32.90 -> got results

I did a long search and said that the problem is in the field type of Mysql.
I should use DECIMAL instead of FLOAT.

Now comes my doubt.

I run the risk of losing data by running the query to change the type in Mysql from FLOAT(8.2) to DECIMA(8.2)?
CHANGE COLUMN total total DECIMAL(8, 2)

ALTER TABLE `pedidos` CHANGE COLUMN `total` `total` DECIMAL(8, 2) UNSIGNED NULL DEFAULT 0.00  COMMENT '' AFTER `pedido_total`
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.