数值函数 - round

适用范围:SQL Server

返回与参数最接近的整数。 如果有多个这样的数,将返回最接近正无穷的那个数。 例如:

如果参数为 2.5, 则 round() 返回 3。

如果参数为 2.4999, 则 round() 返回 2。

如果参数为 -2.5,round () 返回 -2。

如果参数为空序列, round() 将返回空序列。

语法

  
fn:round ( $arg as numeric?) as numeric?  

参数

$arg
将应用该函数的数字。

注解

如果$arg的类型是三个数值基类型之一,即 xs:floatxs:doublexs:decimal,则返回类型与$arg类型相同。 如果$arg的类型是从其中一个数值类型派生的类型,则返回类型为基数值类型。

如果对 fn:floorfn:ceilingfn:round 函数的输入为 xdt:untypedAtomic、非类型化数据,则隐式转换为 xs:double

任何其他类型都会生成静态错误。

示例

本主题针对 AdventureWorks 数据库中各种 xml 类型列中存储的 XML 实例提供 XQuery 示例。

可以在 ceiling 函数(XQuery)将工作示例用于 round() XQuery 函数。 只需将查询中的 ceiling() 函数替换为 round() 函数。

实现限制

限制如下:

  • round() 函数将整数值映射到 xs:decimal。

  • xs:double 和 xs:float 值的 round() 函数在 -0.5e0 和 -0e0 之间映射到 0e0 而不是 -0e0。

另请参阅

floor 函数 (XQuery)
ceiling 函数 (XQuery)