XSLT2.0如何对数字进行舍入?1.45632=>;1.46
如何在XSLT2.0中对数字进行舍入 例如,它的工作原理如下:XSLT2.0如何对数字进行舍入?1.45632=>;1.46,xslt,xslt-2.0,Xslt,Xslt 2.0,如何在XSLT2.0中对数字进行舍入 例如,它的工作原理如下: 1.4367 => 1.44 1.3218 => 1.32 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude
1.4367 => 1.44
1.3218 => 1.32
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<MyTable>
<xsl:value-of select="xs:decimal(MyValue)"/>
</MyTable>
</xsl:template>
</xsl:stylesheet>
您可能正在寻找函数 同样,在XSLT2.0/XPath2.0中,可以使用
xs:decimal
类型在不损失精度的情况下工作
大概是这样的:
1.4367 => 1.44
1.3218 => 1.32
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<MyTable>
<xsl:value-of select="xs:decimal(MyValue)"/>
</MyTable>
</xsl:template>
</xsl:stylesheet>
尝试使用舍入功能:
<xsl:value-of select="round(NUMBER_TO_ROUND*100) div 100"/>
您可能还想看看round-half-to-even(),它执行“银行家四舍五入”,并允许您指定小数位数。