Re: [xsl] Re: using format-number() for aligned text output

Subject: Re: [xsl] Re: using format-number() for aligned text output
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 28 Mar 2001 17:42:10 +0100
Hi Ken,

> I was anticipating format-number(price,'####0.00') to always produce
> a string of 8 characters in length, yet both processors I have (XT
> and Saxon) are Java based and are using the Java library which is
> known to have other problems for this function.

I thought that, since the format-number() function is specifically
based on Java's DecimalFormat class, that using the Java library would
be *more* reliable than copying the functionality in another language?

> Any alternative interpretations out there for the specification
> wording of: "digit specifies the character used for a digit in the
> format pattern; the default value is the number sign character (#)"?
> Would anyone else expect the "#" to produce a space if no digit is
> there? If that isn't the behaviour, then what is the utility of the
> "#"?

In the format pattern, the # stands for an optional digit and the 0
stands for a required digit.  So:

  format-number(12345, '#,##0.00') => '12,345.00'
  format-number(1.5,   '#,##0.00') => '1.50'
  format-number(0.543, '#,##0.00') => '0.54'
  format-number(12345, '#,###.##') => '12,345'
  format-number(1.5,   '#,###.##') => '1.5'
  format-number(0.543, '#,###.##') => '.54'

You need to have #s as well as 0s to allow you to specify the grouping
size in numbers without getting leading 0s all over the place, and to
specify the maximum number of decimal digits without forcing there to
be decimal digits.

Basically, as far as I can tell format-number() can only be used to
pad numbers with zero digits, not with any other character.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread