zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    C#windows向窗体传递泛型类
    phoenix与spark整合
    phoenix创建二级索引
    git
    socket详解
    切片
    通过串口读写数据
    Python 跳出多重循环
    Python从json中提取数据
    Python 字典
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/13755740.html
Copyright © 2011-2022 走看看