Jump to content

sum function returns wrong amount ?


Recommended Posts

Hello Readers, as a noob to xpath and xslt i played around with the online xslt at the w3schools website.I added a few lines including a sum to get the amount of all prices. like this: <th><xsl:value-of select='sum(catalog/cd/price)'/></th> It returns an amount of:237.00000000000003 I tried some other values as prices but sometimes i got the right amount sometimes amounts with lots of digits after the dot. Any ideas how to get the right amount ? Thanks, Best RegardsDirk <?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> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> <th>Price</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> <td><xsl:value-of select="price"/></td> </tr> </xsl:for-each> <tr bgcolor="#9acd32"> <th> </th> <th>Summe:</th> <th><xsl:value-of select='sum(catalog/cd/price)'/></th> </tr> </table> </body> </html></xsl:template></xsl:stylesheet>

Edited by Dirk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...