skip to Main Content

I have a table structure like this:

Table Name: tbl_inventory_stock
id, INT, Primary Key
product_id, INT
store_id, INT
inventory_stok FLOAT

The value of a record that I want to update is like this:

id: 622
product_id: 2364
store_id: 6
inventory_stok: 2382980

Then I change the inventory_stok to 2382979 both directly from the table in phpmyadmin or executing syntax like this:

UPDATE `tbl_inventory_store` SET `inventory_stok` = '2382979' WHERE `tbl_inventory_store`.`id` = 622;

PHPMyAdmin displays the "0 row affected" and the inventory_stok value won’t change. It’s still 2382980.

Does anybody know why? I’ve been struggling for days, please help.

2

Answers


  1. FLOAT is approximate datatype with low precision.

    SELECT CAST(2382979 AS FLOAT)
    
    CAST(2382979 AS FLOAT)
    2382980

    fiddle

    Use more precise datatype. Either DOUBLE or DECIMAL (preferred).

    Login or Signup to reply.
  2. Assuming there is a typo in the question table name float is just not a useful datatype amend to int using alter

    alter table <table>
    modify column inventory_stok int;
    

    then update

    see https://dbfiddle.uk/6a-Gl7Uv

    Can’t do this? then you cannot achieve what you set out to do..

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search