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) |