MySQL Float Type

I have a MySQL table with a column of type float (10, 6).

If I insert 30.064742 into the column, the value stored in the database is 30.064741.

Why?

+3
source share
2 answers

Floating point numbers imply a degree of inaccuracy. Use the DECIMAL column if you need to save each digit.

+4
source

This is a common problem with rounding numbers to precision, which can be stored in a database. Floats are rounded to multiple powers of two. If you need something that is easier to think about, you can use the decimal type, which will be rounded to ten values.

:

, , . ( , .)

+2

Source: https://habr.com/ru/post/1761721/


All Articles