skip to Main Content

Table structure image

The column amount of table is type of Float datatype.

when I’m inserting a new record with the amount value 999999999 it gets automatically converted to 1000000000.0

I’m using Python3.10.2, Flask 2.2.2, Flask-SQLAlchemy 3.0.2, Flask-Migrate 4.0.0 and MySQL Database system

I tried both negative and positive values in negative the result is same but with negative sign

I want to insert 999999999 value as it is in the table.

2

Answers


  1. I think the data type needs to be in the right format maybe an Int64 or 32 as opposed to a float, currency or decimal type. Note this answer: The FLOAT and DOUBLE types represent approximate numeric data values. MySQL uses four bytes for single-precision values .. Why does MySQL round floats way more than expected?

    Login or Signup to reply.
  2. FLOAT datatype is an approximate numeric data value. You may experience rounding errors as it is uses four bytes for the data (DOUBLE uses eight bytes).

    You should consider using DECIMAL datatype instead.

    See a dbfiddle

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