1

I am working with mysql. I created a column in database called "balance" and the datatype for this column is "DECIMAL(12,6)".

So whenever I try to update 4 digits after the decimal point then the last two digits are showing random values (e.g. balance is showing 4444.888672 for the following query).

Here is my current query

UPDATE `table` SET `balance` = '4444.8888' WHERE `token_address` = 'abc123' 
2
  • I cannot reproduce your issue dbfiddle.uk/_8e_V3jG Commented Nov 25, 2022 at 8:37
  • It sounds like balance is actually FLOAT. Please provide SHOW CREATE TABLE. Commented Nov 26, 2022 at 4:42

1 Answer 1

1

Sounds like common float overflow issue, where decimal part does not fit into memory and is cut off.

In our system we use INT's instead. So you would save into database 44448888000 and in PHP you would parse it as $row['balance'] / 1000000

Sign up to request clarification or add additional context in comments.

3 Comments

can i save with decimal if yes then how ? means how can i fix this ?
@RajniDhiman Where it's showing like that? In database itself or in back-end (php?)
In Database (phpmyadmin)