How to store decimal in MySQL?

前端 未结 6 912
谎友^
谎友^ 2020-12-05 06:35

I\'ve tried using DECIMAL with (2,2) but it won\'t let me use this.

I simply want to store a number, for example 7.50 or 10.50. I need to keep both numbers after th

6条回答
  •  借酒劲吻你
    2020-12-05 07:03

    CREATE TABLE `salary` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `salary` DECIMAL(10,2) DEFAULT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
    

    DECIMAL(10,2) indicates that salary will hold a total of 10 digits out of which 2 will be after the decimal.

    i.e.

    8 digits before decimal and 2 digits after decimal.

提交回复
热议问题