create table table1 (d decimal(18,2));
insert into table1 select 5.55;
insert into table1 select 6.00;
insert into table1 select 6;
insert into table1 select 7.21;
select * from table1
select * from table1 where d>convert(int,d);
select * from table1 where d=round(d,0);
在mysql中,round函數用於數據的四舍五入,它有兩種形式:
1、round(x,d) ,x指要處理的數,d是指保留幾位小數
這里有個值得注意的地方是,d可以是負數,這時是指定小數點左邊的d位整數位為0,同時小數位均為0;
2、round(x) ,其實就是round(x,0),也就是默認d為0;
下面是幾個實例
1、查詢: select round(1123.26723,2);
結果:1123.27
2、查詢: select round(1123.26723,1);
結果: 1123.3
3、查詢: select round(1123.26723,0);
結果:1123
4、查詢: select round(1123.26723,-1);
結果: 1120
5、查詢: select round(1123.26723,-2);
結果:1100
6、查詢: select round(1123.26723);
結果:1123