round 函数 (XPath)
返回与参数最接近的整数值。
number round(number)
备注
如果有两个这样的数字,将返回与正无穷大最接近的数字。
如果参数为 NaN,则返回 NaN。
如果参数为正无穷大,将返回正无穷大。
如果参数为负无穷大,将返回负无穷大。
如果参数为正零,将返回正零。
如果参数为负零,将返回负零。
如果参数小于零但是大于等于 -0.5,将返回负零。
对于最后两种情况,调用 round() 函数的结果与加上 0.5 后再调用 floor() 函数的结果不同,因为在这种情况下将返回正零。
示例
该示例阐释 round() 表达式。
XML 文件
无;XSLT 文件调用自身。
XSLT 文件 (round.xsl)
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="round.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
round(2.6) =
<xsl:value-of select='round(2.6)'/>
<br/>round (2.4) =
<xsl:value-of select='round (2.4)'/>
<br/>round(2.5) =
<xsl:value-of select='round(2.5)'/>
<br/>round(-1.6) =
<xsl:value-of select='round(-1.6)'/>
<br/>round(-1.5) =
<xsl:value-of select='round(-1.5)'/>
</xsl:template>
</xsl:stylesheet>
格式化输出
round(2.6) = 3 round (2.4) = 2 round(2.5) = 3 round(-1.6) = -2 round(-1.5) = -1
处理器输出
<?xml version="1.0"?>
round(2.6) =
3<br />round (2.4) =
2<br />round(2.5) =
3<br />round(-1.6) =
-2<br />round(-1.5) =
-1