您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql 中 int型对小数位的处理

2024/5/3 5:39:20发布53次查看
在mysql中,int型表示整型,如果遇到非整型,如何处理呢?下面创建存储过程测试一下 create definer=`root`@`localhost` procedure `test`() begin declare x int default 0; declare y int default 0; declare y1 int default 0; declare y2 int default 0;
 在mysql中,int型表示整型,如果遇到非整型,如何处理呢?下面创建存储过程测试一下
create definer=`root`@`localhost` procedure `test`()
begin
  declare x int default 0;
  declare y int default 0;
  declare y1 int default 0;
  declare y2 int default 0;
     set x=54;
     set y=51*0.2;
     set y1=54*0.2;
     set y2=1.2;
     select y;
     select y1;
     select y2;
end
执行
mysql> call test;
+------+
| y    |
+------+
|   10 |
+------+
1 row in set (0.00 sec)
+------+
| y1   |
+------+
|   11 |
+------+
1 row in set (0.00 sec)
+------+
| y2   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)
可以看出,mysql int型对于非整型进行四舍五入处理,对数值严格要求的不能这样随意赋值或转换,必须使用精确的类型表示。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product