MySQL field type for storing decimal places

I am creating a database that will contain products with several columns "height" (in meters, for ex 7.79 or 12.8). No more than 2 digits before and 2 after the decimal point. What type of field should I use for this?

If I use a decimal (2,2) attempt to insert 7.79 in phpmyadmin, I get the error message "Warning: # 1264 Value out of range for column" working_height "in row 1

I will use this database for search, so I should be able to run a query like "select all products whose height is greater than 7".

+4
source share
3 answers

People will say to use decimal (s, d ), but how to save values ​​as integers, in centimeters instead of meters? Easier to compare (without loss of accuracy).

Only my two cents.

+8
source

You are looking for decimal (4,2) - in general, decimal (m, n) means m full digits and n to the right of the decimal point. Docs are here .

Thus, decimal (2.2) can store two complete digits, as to the right of the decimal point. This explains the error you see.

+10
source

Try instead of DECIMAL (4.2)

Refer to: MySQL numeric types

+4
source

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


All Articles