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="";> <xsl:output method="text"/>

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


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
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) ;-)


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

XSL-List info and archive:

Current Thread