mysql中的round函數,判斷某個字段是否是小數


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM