Problems with inserting data in float field in MYSQL

Posted on

Question :

I have a problem inserting a value into a field in the table, this field is as float (15,6).

I circled an insert here

INSERT INTO valores (valor) VALUES ('1160.480000');

Why does he enter the value as 1160.479980?

    

Answer :

Formalizing the answer:
The error occurs because float does not store exact details – but rather (monetary values), we should use decimal . …

The decimal in MySQL has the capacity to store a maximum of 65 digits, and of these, 30 digits can be used for the decimal.

This response further details the
Another post on the subject .

ALTER TABLE valores MODIFY valor decimal(15,6);

INSERT INTO valores (valor) VALUES (1160.480000);

    

Leave a Reply

Your email address will not be published. Required fields are marked *