I'm trying to get the value of a number to 2 dec places from my xml.
XML:<Quantity>0.0050</Quantity>
XSL:<xsl:value-of select="format-number($quantity, '####0.00')" />
However XSL seems to have a problem with this value and outputs 0.00
in one area of the page and 0.01
in the other. Of course in this situation it is favourable to have 0.01
output in all areas.
Another area has the value 4.221
yet the XSL is outputting 4.23
.
I do realise that format-number
as a method converts a number to a string.
Not sure how to fix this.
EDIT:
Ok after a bit of mucking around i found that this works:
<xsl:value-of select='format-number( round(100*$quantity) div 100 ,"##0.00" )' />
Via this website
As this guy mentions XSL uses 'bankers rounding' to round to even numbers instead of the bigger ones.
The solution hardly seems elegant, and means adding a ton of extra functions to an already bulky and complicated XSL file. Surely i'm missing something?
See Question&Answers more detail:os