[英]xslt 2.0 how to round number? 1.45632 => 1.46
如何在xslt 2.0中舍入數字
例如,它將像這樣工作:
1.4367 => 1.44
1.3218 => 1.32
嘗試使用圓函數:
<xsl:value-of select="round(NUMBER_TO_ROUND*100) div 100"/>
您可能正在尋找format-number()函數。
同樣在In XSLT 2.0 / XPath 2.0中,可以使用xs:decimal
類型來工作而不會損失精度。
像這樣的東西:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.