gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 22:01:34 26 4
gpt4 key购买 nike

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

我尝试使用Decimal数据类型

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

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

最佳答案

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

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;

关于MySQL 数据库字段十进制数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32597863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com