Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Trevor Nash <tcn@me...>  20021018 09:59:18

Hi David, >I came across a bug in version 7.2 of Saxon, or at least an=20 >inconsistency. The formatnumber function sometimes rounds=20 >up and sometimes rounds down when the number is exactly=20 >halfway between the round up and round down values. =20 >If you run the following xsl: > >... you get the following results: > >formatnumber(227.55, "0.0") =3D 227.6 >formatnumber(227.65, "0.0") =3D 227.6 > I have not actually done the sums, but I suspect this is a consequence of XPath numbers being represented as floating point. In this system many fractional numbers cannot be represented exactly, because they end up as a recurring binary (just as you cannot represent 1/3 in decimal notation). So 227.55 might be 227.55000000001 and 227.65 > 227.64999999999999 So the numbers are not 'exactly halfway between'. If this matters to you, for example in financial calculations, then you have to use algorithms which avoid these rounding errors. Using integers is one strategy: 22755 and 22765 rounded to the nearest ten should give the result you expect. This may not be adequate if your calculations involve division though. This isn't specific to XSLT/XPath  the same problem crops up in many other programming languages. Regards, Trevor Nash Melvaig Software Engineering Limited voice: +44 (0) 1445 771 271=20 email: tcn@... web: http://www.melvaig.co.uk 