zoukankan      html  css  js  c++  java
  • Oracle四舍五入,向上取整,向下取整

    用oracle sql对数字进行操作: 取上取整、向下取整、保留N位小数、四舍五入、数字格式化
    
    取整(向下取整): 
    select floor(5.534) from dual;
    select trunc(5.534) from dual;
    上面两种用法都可以对数字5.534向下取整,结果为5.
    
    如果要向上取整 ,得到结果为6,则应该用ceil
    select ceil(5.534) from dual;
     
    
    四舍五入: 
    SELECT round(5.534) FROM dual;
    SELECT round(5.534,0) FROM dual;
    SELECT round(5.534,1) FROM dual;
    SELECT round(5.534,2) FROM dual;
    结果分别为 6,  6,  5.5,  5.53
     
    
    保留N位小数(不四舍五入)按位数截取: 
    select trunc(5.534,0) from dual;
    select trunc(5.534,1) from dual;
    select trunc(5.534,2) from dual;
    结果分别是 5,5.5,5.53,其中保留0位小数就相当于直接取整了。
     
    
    数字格式化: 
    select to_char(12345.123,'99999999.9999') from dual;
    结果为12345.123
    
    select to_char(12345.123,'99999999.9900') from dual;
    小数后第三第四为不足补0,结果为12345.1230
    
    select to_char(0.123,'99999999.9900') from dual;
    select to_char(0.123,'99999990.9900') from dual;
    结果分别为 .123, 0.123
  • 相关阅读:
    抽样调查
    一次项目上线发布的感想
    Nginx failing to load CSS and JS files (MIME type error)
    securecrt-active
    golang-http-post
    remove-weknow-ac from mac chrome
    批量写入redis
    golang 修改数组中结构体对象的值的坑
    golang使用json生成结构体
    json定义
  • 原文地址:https://www.cnblogs.com/wangjp-1233/p/10252431.html
Copyright © 2011-2022 走看看