...

Format number of decimal places

HairyTeeth
05-30-2003, 02:52 AM
Hi,
I probably can't see the woods for the trees but...

I just started using XML yesterday. Everything is going ok thus far except I'm having trouble displaying 2 digits after the decimal point when I sum() a prices element in the stylesheet (xsl).

For example...
If the price total equals $57.50, the sum(//price) returns $57.5
If the price total equals $57.00, the sum(//price) returns $57

I am trying to return $57.50 and $57.00.

I have converted the sum(//price) value to a string and stuffed that value into a variable (strTotal), in the hope of using one of the xpath string functions to manipulate the appropriate number of '0''s after the decimal point in the strTotal variable, but I'm a bit lost from there. Heres the code snippet I'm working with:

<tr>
<th colspan="2">Total</th>
<xsl:variable name="strTotal" select="string(sum(//price))" />
<td>$<xsl:value-of select="$strTotal" /></td>
</tr>

I've had a look around the net but didn't find anything of use. Suggestions, comments much appreciated.

HairyTeeth
05-30-2003, 04:06 AM
I found it...

<tr>
<th colspan="2">Total</th>
<td>$<xsl:value-of select="format-number(sum(//price),'#,###.00')" /></td>
</tr>


Good in Ie5.01 and Moz1.3



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum