0

If i use the SUM function to sum those node with d.p. value....the output in sometimes are look strange......

XML File
<allgroup>
<group_1 id="1">
<salary>100000.01</salary>
</group_1>
<group_1 id="2">
<salary>89000.02</salary>
</group_1>
<group_1 id="3">
<salary>89000.03</salary>
</group_1>
<group_1 id="4">
<salary>89000.04</salary>
</group_1>
<group_1 id="5">
<salary>89000.05</salary>
</group_1>
</allgroup>

XSL File
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding='utf-8'/>
<xsl:template match="allgroup">
<xsl:element name="TEST_SUM">
<xsl:value-of select="sum(/allgroup/group_1/salary)"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

RESULT
<?xml version="1.0" encoding="utf-8"?><TEST_SUM>456000.14999999996</TEST_SUM>

How can i get the result as 456000.15? Need to use the function format-number? format-number will round the value?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by fpmurphy
0

What processor are you using? Using xsltproc as my stylesheet processor the expected result was returned.

This also worked using xsltproc:

<xsl:element name="TEST_SUM">
        <xsl:variable name="fpm" select='sum(/allgroup/group_1/salary)' />
        <xsl:value-of select='format-number($fpm, "#.00")' />
     </xsl:element>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.