我在使用xsl时遇到了不一致的问题,
这里是XML:
"输出结果为:"
但是预期的输出为,
为什么输出值是523.4100000000001?如何在不四舍五入的情况下得到523.41?
这里是XML:
<Rate>
<TotalRate>506.41</TotalRate>
<TotalTax>17</TotalTax>
<Currency>INR</Currency>
</Rate>
and xsl,
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<TotalAmount>
<xsl:value-of select="Rate/TotalRate + Rate/TotalTax"/>
</TotalAmount>
</xsl:template>
</xsl:stylesheet>
"输出结果为:"
<TotalAmount xmlns:fo="http://www.w3.org/1999/XSL/Format">523.4100000000001</TotalAmount>
但是预期的输出为,
<TotalAmount xmlns:fo="http://www.w3.org/1999/XSL/Format">523.41</TotalAmount>
为什么输出值是523.4100000000001?如何在不四舍五入的情况下得到523.41?
format-number()
参数。此外,请参阅我的XSLT 2.0解决方案,其中您可以使用xs:decimal
类型进行精确计算。 - Dimitre Novatchev