trunc与round
- number 需要截尾取整的数字。
- num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。
作用:截断数字和时间
- TRUNC()函数截取时不进行四舍五入
- 只能作用时间和数字
select trunc(sysdate) from dual; --2017/11/7 今天的日期为2017-11-07
select trunc(sysdate, 'mm') from dual; --2017/11/1 返回当月第一天.
select trunc(sysdate,'yy') from dual; --2017/1/1 返回当年第一天
select trunc(sysdate,'dd') from dual; --2017/11/7 返回当前年月日
select trunc(sysdate,'yyyy') from dual; --2017/1/1 返回当年第一天
select trunc(sysdate,'d') from dual; --2017/11/5 (星期天)返回当前星期的第一天
select trunc(sysdate, 'hh') from dual; --2017/11/7 17:00:00 当前时间为17:34
select trunc(sysdate, 'mi') from dual; --2017/11/7 17:34:00 TRUNC()函数没有秒的精确
select trunc(123.458) from dual; --123
select trunc(123.458,0) from dual; --123
select trunc(123.458,1) from dual; --123.4
select trunc(123.458,-1) from dual; --120
select trunc(123.458,-4) from dual; --0
select trunc(123.458,4) from dual; --123.458
select trunc(123) from dual; --123
select trunc(123,1) from dual; --123
select trunc(123,-1) from dual; --120
- number 待做截取处理的数值
- decimals 指明需保留小数点后面的位数。可选项,忽略它则截去所有的小数部分,并四舍五入。如果为负数则表示从小数点开始左边的位数,相应整数数字用0填充,小数被去掉。需要注意的是,和trunc函数不同,对截取的数字要四舍五入
作用:四舍五入一个小数
- 当decimals作用于小数点后的数字就是四色五入
- 当decimals作用于小数点钱的数字而是截断的效果
测试:
select round(123.456) from dual; --123
select round(123.456,0) from dual; --123
select round(123.456,1) from dual; --123.5
select round(123.456,2) from dual; --123.46
select round(123.456,-1) from dual; --120
select round(123.456,-2) from dual; --100
select round(123,1) from dual; --123
select round(123,-1) from dual; --120
trunc与round的更多相关文章
- 【测试】trunc和round的区别
trunc是截断:round是四舍五入:下面通过一个例子具体看一下trunc和round的不同 SQL),trunc() from dual; TRUNC() TRUNC() ------------ ...
- Oracle trunc和round的区别
1.关于trunc 和round函数比较 整体概括: round函数 四舍五入trunc函数 直接截取 对于时间: Round函数对日期进行"四舍五入",Trunc函数对日期进行截 ...
- Excel 数学函数(一):INT、TRUNC、ROUND、ROUNDUP 和 ROUNDDOWN
前言 INT.TRUNC.ROUND.ROUNDUP 和 ROUNDDOWN 都是对一个数进行取舍,但是,各自的取舍的方式不一样. INT 函数只有一个参数:TRUNC.ROUND.ROUNDUP 和 ...
- oracle之trunc与round
round(x[,y]) 功能:返回四舍五入后的值 参数:x,y,数字型表达式,如果y不为整数则截取y整数部分,如果y>0则四舍五入为y位小数,如果y小于0则四舍五入到小数点向左第y位. 返回: ...
- Delphi 数学函数:常用的几个数学函数(Power、Abs、Int、Trunc、Round、Frac、sqr、sqrt)
Delphi 常用的几个数学函数 1 Power函数,求次方 定义:function Power(X,Y): (Same type as parameter); 说明:X可以是整型,也可以是实型:返回 ...
- Oracle函数:trunc、round、ceil和floor
1.trunc函数 1).trunc(date) 格式:trunc(date,fmt) trunc用于截取时间,即便你指定不同的格式类型,返回的类型始终都是时间类型. 示例: with dates a ...
- Delphi 常用函数(数学函数)round、trunc、ceil和floor
源:Delphi 常用函数(数学函数)round.trunc.ceil和floor Delphi 常用函数(数学) Delphi中怎么将实数取整? floor 和 ceil 是 math unit 里 ...
- oracle常用函数及示例
学习oracle也有一段时间了,发现oracle中的函数好多,对于做后台的程序猿来说,大把大把的时间还要学习很多其他的新东西,再把这些函数也都记住是不太现实的,所以总结了一下oracle中的一些常用函 ...
- C# 取整函数
向上取整math.ceiling(1) = 1math.ceiling(1.1) = 2math.ceiling(1.5) = 2向下取整math.float(1) = 1math.float(1.1 ...
随机推荐
- Linux学习总结(1)——Linux命令大全完整版
Linux命令大全完整版 目 录I 1. linux系统管理命令1 adduser1 chfn(change finger information)1 chsh(change shell)1 d ...
- HDU——T 1166 敌兵布阵
http://acm.hdu.edu.cn/showproblem.php?pid=1166 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- SQL Server 为代码减负之存储过程
存储过程能够用来提高数据库的查询效率.由于它事先被编译过.被储存于内存中,每次执行前.不必被从新编译,所以效率非常高. 存储过程是一组sql增删改查的集合,假设程序中的一个功能涉及到对数据库的 ...
- OpenCASCADE7.3.0 is available for download
OpenCASCADE7.3.0 is available for download OPEN CASCADE is pleased to announce a new public release ...
- RvmTranslator6.0 - Dassault Systemes 3DXML
RvmTranslator6.0 - Dassault Systemes 3DXML eryar@163.com 1. Introduction RvmTranslator can translate ...
- 5.cocos2d锚点
创建一个层T1LayerAnchorPoint AppDelegate.cpp bool AppDelegate::applicationDidFinishLaunching() { // initi ...
- POJ 2458 DFS+判重
题意: 思路: 搜+判重 嗯搞定 (听说有好多人用7个for写得-.) //By SiriusRen #include <bitset> #include <cstdio>0 ...
- Objective-C ,ios,iphone开发基础:UIAlertView使用详解
UIAlertView使用详解 Ios中为我们提供了一个用来弹出提示框的类 UIAlertView,他类似于javascript中的alert 和c#中的MessageBox(); UIAlertVi ...
- 使用Cygwin在Windows上体验Linux的快感
前言 记得大学的时候就以前使用过Cygwin,可惜当时没有发现她的美,我相信如今大多数朋友可能会更加倾向于使用Git或者干脆直接使用虚拟机以及原生Unix. 只是对于刚进入Linux的世界新人来说,使 ...
- LeetCode 136 Single Number(仅仅出现一次的数字)
翻译 给定一个整型数组,除了某个元素外其余元素均出现两次. 找出这个仅仅出现一次的元素. 备注: 你的算法应该是一个线性时间复杂度. 你能够不用额外空间来实现它吗? 原文 Given an array ...