[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: simple question

Subject: Re: simple question
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 25 Feb 2002 17:14:07 +0000
format number decimals places xsl
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


Current Thread
  • simple question
    • Arun Ramdas - Tue, 19 Feb 2002 13:42:29 -0500 (EST)
      • <Possible follow-ups>
      • Arun Ramdas - Thu, 21 Feb 2002 17:41:24 -0500 (EST)
        • Jeni Tennison - Mon, 25 Feb 2002 12:12:36 -0500 (EST) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.