MySQL数据库字段十进制数据类型

时间:2015-09-16 00:35:35

标签: mysql

我想要一个带有两位小数和1位小数的数字字段,它可以识别1.1和1.10,2.2,2.20等。

我尝试使用Decimal数据类型

Create table Number (Sample decimal (3,2);

当我尝试输入1.1时,它输出1.10,我该怎么办?

1 个答案:

答案 0 :(得分:0)

当您选择表格时,检查第二个小数,并根据需要进行截断。请参阅以下代码:

select case when ((1.10*100)%10) > 0 then 1.10 else truncate(1.10, 1) end;
select case when ((1.12*100)%10) > 0 then 1.12 else truncate(1.12, 1) end;

您可以将其用作select case when ((mydecimalcolumn)%10) > 0 then mydecimalcolumn else truncate(mydecimalcolumn, 1) end mydecimalcolumn, othercolumn1, othercolumn2 from mytable;