round Function
Returns an integer closest in value to the argument.
number round(number)
Remarks
If there are two such numbers, the one that is closest to positive infinity is returned.
If the argument is NaN, NaN is returned.
If the argument is positive infinity, positive infinity is returned.
If the argument is negative infinity, negative infinity is returned.
If the argument is positive zero, positive zero is returned.
If the argument is negative zero, negative zero is returned.
If the argument is less than zero but greater than or equal to -0.5, negative zero is returned.
For the last two cases, the result of calling the round()
function is not the same as the result of adding 0.5 and then calling the floor()
function because positive zero will be returned in such cases.
Example
This example demonstrates round()
expressions.
XML File
None; the XSLT file calls itself.
XSLT File (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>
Formatted Output
round(2.6) = 3 round (2.4) = 2 round(2.5) = 3 round(-1.6) = -2 round(-1.5) = -1
Processor Output
<?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