Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1417701
  • 博文数量: 254
  • 博客积分: 4173
  • 博客等级: 中校
  • 技术积分: 3400
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-03 21:24
个人简介

不为失败找借口,只为成功找方法!

文章分类

全部博文(254)

文章存档

2021年(3)

2020年(1)

2019年(2)

2017年(10)

2016年(6)

2015年(19)

2014年(24)

2013年(19)

2012年(52)

2011年(118)

分类: Oracle

2015-05-28 13:52:17

Ceiling函数: 取进一值,此函数将结果集内容按规则自动进一,如3.1进1则为4,不是按ROUND规则来取数。
Truncate函数: 取减一值,此函数将结果集内容按规则自动减一,如3.58,减一则为3.5。具体用法如下!

Ceiling
Description 

Determines the smallest whole number that is greater than or equal to a specified limit.

Syntax 

Ceiling ( n )

Argument Description
n The number for which you want the smallest whole number that is greater than or equal to it
Return value 

The datatype of n. Returns the smallest whole number that is greater than or equal to n. If n is null, Ceiling returns null. 

举例:The Examples:

These statements set num to 5:

decimal dec, num

dec = 4.8

num = Ceiling(dec)

These statements set num to -4:

decimal num

num = Ceiling(-4.2)

num = Ceiling(-4.8)


Truncate
Description 

Truncates a number to the specified number of decimal places.

Syntax 

Truncate ( x, n )

Argument Description
x The number you want to truncate
n The number of decimal places to which you want to truncate x (valid values are 0 through 18)
Return value 

Decimal. Returns the result of the truncation if it succeeds and null if it fails or if any argument is null.
Using Truncate on a computed field    A real number loaded into a floating point register (used for calculation) is represented as precisely as the binary storage will permit. For example, the real number displayed as 2.07 is actually stored as 2.0699999999999997. 

Truncating such a number may not give the expected result. To avoid this problem, you can change the initial real datatype to long, Integer, or decimal, or you can append a constant in the truncate argument: Truncate (x + 0.0000001, n )

举例:The Examples:

This statement returns 9.2:

Truncate(9.22, 1)

This statement returns 9.2:

Truncate(9.28, 1)

This statement returns 9:

Truncate(9.9, 0)

This statement returns -9.2:

Truncate(-9.29, 1)

注:以上两个函数的使用之后一般建议与Round或int结合,因为函数的返回结果是带出18位小数点来。可读性不强。
阅读(1903) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~