Re: [xsl] Magic numbers

Subject: Re: [xsl] Magic numbers
From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx>
Date: Tue, 18 Nov 2003 13:47:13 +0000
From: Yago Alvarado <Yago.Alvarado@xxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: "'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'" <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] Magic numbers
Date: Tue, 18 Nov 2003 12:54:49 -0000

Hi everyone!

I have the following xsl code:


<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";> <xsl:output method="text"/>

<xsl:template match="/">
 <xsl:value-of select="100 * .05"/>
</xsl:template>

</xsl:stylesheet>



which works fine and shows the expected result... now...if you change
.05 for .07 you get something totally unexpected (at least is unexpected
to me).

My first thought was blaming the XSLT processor so I tried with another
one...
and I'm getting the same result whatever the processor is...
(MSXML 4 or Saxon 6.5.2)

This only happens using the *magic* number of 7 with any other number it
works just fine and returns the expected result.


Does anyone know why this is happening?
Is is number 7 a truly magical number with undiscovered mathematical powers
or is it just me not understanding what's going on here?
(my vote goes to the second one) ;-)



Regards,
Yago

As you don't say what your results were who knows?
My guess is you got 7.00000000000000001 or 6.9999999999999. This is because binary representation of some decimals using standard techniques is impossibe, similarly to expressing one third in decimal.
You either have to use integer arithmetic, in this case '100 * 7 div 100' or round your answers.


Joe (MVP - xml)

_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection http://www.msn.co.uk/specials/btbroadband



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread