Home  >  Article  >  Database  >  mysql 中 int型对小数位的处理

mysql 中 int型对小数位的处理

WBOY
WBOYOriginal
2016-06-07 15:07:191605browse

在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型对于非整型进行四舍五入处理,对数值严格要求的不能这样随意赋值或转换,必须使用精确的类型表示。


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:ORACLE安装过程要点记录Next article:Oracle中如何用T