This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: simple question
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Arun Ramdas <aramdas at etrade dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 25 Feb 2002 17:14:07 +0000
- Subject: Re: [xsl] simple question
- Organization: Jeni Tennison Consulting Ltd
- References: <E2355928804ED21187B500805F571F500F9B087E@g4ntex1.etrade.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Arun,
> Thanks for ur reply. It was extensive and addressed my need very well. I
> want the number to be formatted in USD currency.
>
> for example, 123456789, needs to be formatted to $123.46M
... OK. I'll take it that you mean:
- if the number is over 1000000000 then you need to have a dollar
sign, then the number divided by 1000000000 and formatted with two
decimal places, then the word 'billion'.
- if the number is over 1000000 then you need to have a dollar sign,
then the number divided by 1000000 and formatted with two decimal
places, then the letter 'M'.
- otherwise, then you need a dollar sign, then the number formatted
with no decimal places.
Which translates to templates that look like:
<xsl:template name="format-price">
<xsl:param name="price" select="number()" />
<xsl:text>$</xsl:text>
<xsl:call-template name="format-number">
<xsl:with-param name="number" select="$price" />
</xsl:call-template>
</xsl:template>
<xsl:template name="format-number">
<xsl:param name="number" select="0" />
<xsl:choose>
<xsl:when test="$number > 1000000000">
<xsl:value-of
select="format-number($number div 1000000000, '0.00')" />
<xsl:text> billion</xsl:text>
</xsl:when>
<xsl:when test="$number > 1000000">
<xsl:value-of
select="format-number($number div 1000000, '0.00')" />
<xsl:text>M</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($number, '#,##0')" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list