This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Formatting numbers
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Formatting numbers
- From: Zak McGregor <zak at mighty dot co dot za>
- Date: Tue, 10 Apr 2001 14:49:31 +0200
- Organization: None
- References: <200104101047.MAA22508@zak.home.dom>
- Reply-To: xsl-list at lists dot mulberrytech dot com
On Tue, 10 Apr 2001 12:47:18 +0200
Zak McGregor <zak@mighty.co.za> wrote:
> Hi all
>
> I need to get numbers in a format that would be suitable for currency
> (eg:
> 5.00 or 3.50 or 1.99 etc), which is simple enough, but I am using
> Sablotron 0.51 which lists format-number() as currently unimplemented.
> Any
> kind peeps out there with an idea of how I could acieve the same effect
> please?
>
Well, I have a solution, but it isn't pretty...
...
<xsl:call-template name="number-pad">
<xsl:with-param name="number-to-format" select="floor(amount*100+0.5)
div 100"/>
</xsl:call-template>
...
<xsl:template name="number-pad">
<xsl:param name="number-to-format" />
<xsl:variable name="zpad"
select="string-length(substring-after($number-to-format,'.'))" />
<xsl:choose>
<xsl:when test="$zpad=0"><xsl:value-of
select="concat($number-to-format,'.00')"/></xsl:when>
<xsl:when test="$zpad=1"><xsl:value-of
select="concat($number-to-format,'0')"/></xsl:when>
<xsl:otherwise><xsl:value-of
select="$number-to-format"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
...
I hope this helps someone else out there...
Cheers
Zak
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list