Decimal(3,2) values in MySQL are always 9.99

前端 未结 2 1384
不知归路
不知归路 2021-02-02 07:41

I have a field, justsomenum, of type decimal(3,2) in MySQL that seems to always have values of 9.99 when I insert something like 78.3. Why?

This is what my table looks l

2条回答
  •  孤街浪徒
    2021-02-02 08:23

    In older versions MySQL DECIMAL(3,2) meant 3 integers to the left of the DP and 2 to the right.

    The MySQL devs have since changed it so the first property (in this case '3') is the complete number of integers in the decimal (9.99 being three numbers), and the second property (in this case '2') stays the same — the number of decimal places.

    It's a little confusing. Basically, for DECIMAL fields, whatever number of integers you want before the DP needs to be added to whatever number of integers you want after the DP and set as your first option.

    Then as has already been said, if you try to enter a number greater than the maximum value for the field, MySQL trims it for you. The problem here is your MySQL configuration. I go into more detail about this on my blog.

提交回复
热议问题