我有两个 xml。有一个金额字段,可以包含 54.2,54.23,54.234,54.234567 等值。
有人请告诉我如何确保输出 xml 中至少出现两位小数。当前 54.2 转换为 54,2 ,但我希望它是 54,20
您可以使用 format-number() 函数将数字转换为给定格式的字符串。
如果使用“#.00##########”格式字符串,则至少会出现两位小数。
如果您有一个 xml 文件,其中可以包含 54.2,54.23,54.234,54.234567 等值:
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<price>54.2</price>
<price>54.23</price>
<price>54.234</price>
<price>54.234567</price>
</catalog>
您可以使用像这样的 xslt 转换数字以获得至少两位小数
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="/catalog/price">
<xsl:value-of select='format-number(., "#.00##########")'/><br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
然后输出:
54.20
54.23
54.234
54.234567
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)