Handle decimal numbers in mysqli

前端 未结 1 365
梦谈多话
梦谈多话 2021-01-17 13:14

I have to put the price of some items inside a mysql table. When creating the table I\'m using DECIMAL(10,2) as I don\'t need more than 2 digits after the comma

1条回答
  •  执笔经年
    2021-01-17 13:25

    DECIMAL(10,2) means that 10 is the maximum number of digits to be used. The 2 specifies that there are two on the right side of the decimal. So this means there are 8 digits left on the left side. See the manual

    As for the datatype, you should use double as this is for decimal numbers.

    Integer has no decimal chars, so it will floor all numbers. String is for text and not numeric values. Blob is for a binary large object, EG: an image

    0 讨论(0)
提交回复
热议问题