Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2011, 12:16 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default Fuzzy maths or what?

I'm kinda flabberghasted with this issue. Can someone explain me what's that weird behaviour.

<xsl:value-of select="0.3 + 0.3 + 0.3"/>

We would expect this to be 0.9 right? Wrong! I'm getting 0.8999999999999999 using Xalan-J !!!

:o(
__________________
Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old February 18th, 2011, 12:30 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well the double number type that XSLT/XPath 1.0 uses is the same as the number type Javascript uses and when you try javascript: alert(0.3 + 0.3 + 0.3); in your browser you will get the same result. The reason is the binary representation of the number. You will need to round your result or (as you use Java) you could move to an XSLT 2.0 processor like Saxon 9 and then use the xs:decimal type instead of the double number type.

Additionally, with XSLT 1.0 if you want a certain format of numbers in your output you can use http://www.w3.org/TR/xslt#format-number.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog

Last edited by Martin Honnen; February 18th, 2011 at 01:00 PM.. Reason: adding link to format-number





Similar Threads
Thread Thread Starter Forum Replies Last Post
Fuzzy control system picoBrain Need help with your homework? 0 April 20th, 2007 09:17 AM
Fuzzy string comparison (2) kobus XSLT 2 October 11th, 2004 07:28 AM
fuzzy string comparison kobus XSLT 0 September 22nd, 2004 05:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.