我创建了表格,如下所示:
create table sample_tbl
(
decimal_column decimal(19,2) null
);
现在,当我使用简单的插入命令插入到该表中时:
insert into sample_tbl values (18.939);
MySQL将其存储为18.94,我应该如何解决这个问题?我想存储实际值:18.93
最佳答案
您插入的值已正确舍入为 18.94
。
您想要的是将值截断为小数点后两位,因此请使用函数 truncate()
:
insert into sample_tbl values (truncate(18.939, 2));
关于MySQL在插入数据库时更改decimal(19, 2)的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61007398/