W3C home > Mailing lists > Public > www-xsl-fo@w3.org > December 2008

Re: Currency format in a PDF - another question concerning cents portion

From: Daniel H. Peger <peger@gmx.net>
Date: Tue, 2 Dec 2008 19:46:39 +0100
To: www-xsl-fo@w3.org
Message-Id: <200812021946.39870.peger@gmx.net>

Hi,

actually I have no idea of what exactly you are trying to do with your code. 
But if your only problem is to get a decimal point instead of the comma to 
separate the decimal place of the number, i'd have a look at the example on 
http://www.w3schools.com/xsl/el_decimal-format.asp and adapt it to your 
needs:

<xsl:decimal-format name="us"
decimal-separator="." grouping-separator=","/>
 
<xsl:template match="/">
<xsl:value-of 
select="format-number(26825.8, '#.###,00', 'us')"/>
</xsl:template>

Haven't tried it but it should do the trick, if you want to call it a trick...

Regards

Am Dienstag 02 Dezember 2008 08:05:30 schrieb Chawla:
> Hi,
>
> I am facing the same issue. Instead of 1,70 or 0,33..i want 1.70 or 0.33
> respectively as my output.
> I dont know what is wrong with my code. Please suggest.
>
>
>                       <xsl:choose>
>
>                       <xsl:when test="(UNIT_PRICE,1,1 > 1) and
> (substring-before(UNIT_PRICE,',') > 0)">
>                                       <fo:table-cell
> xsl:use-decimal-format="euro2"> <fo:table-cell
> xsl:use-attribute-sets="table.cell5">  <fo:block
> xsl:use-attribute-sets="form_data1">
>                                                       <xsl:value-of
> select="format-number(substring-before(UNIT_PRICE,','),'#.###','euro2')"/>,
><xsl:if test="(substring(substring-after(UNIT_PRICE,','),3,1)) >
> 4"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,','),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,','),3,1))
> =''"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,','),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,','),3,1)) =
> 1"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,','),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,','),3,1)) =
> 2"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,','),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,','),3,1)) =
> 3"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,','),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,','),3,1)) =
> 4"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,','),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,','),2,1)) =
> ''"><xsl:value-of
> select="((substring(substring-after(UNIT_PRICE,','),1,1))-(substring(substr
>ing-after(UNIT_PRICE,','),1,1)))"/></xsl:if>
>
> </fo:block>
>                                       </fo:table-cell>
>                                      </fo:table-cell>
>                               </xsl:when>
>                                  <xsl:when 
test="(substring(UNIT_PRICE,1,1)=',')">
>                                       <fo:table-cell
> xsl:use-attribute-sets="table.cell5">  <fo:block
> xsl:use-attribute-sets="form_data1">
>                                                 <xsl:value-of  select="UNIT_PRICE"/>
>                                                </fo:block>
>                                       </fo:table-cell>
>                               </xsl:when>
>                               <!--changed , to . in the following xsl 
value-of for SCR PO-503 -->
>                          <xsl:when test="(UNIT_PRICE,1,1 > 1) and
> (substring-after(UNIT_PRICE,'.') > 0)">
>                                       <fo:table-cell
> xsl:use-decimal-format="euro2"> <fo:table-cell
> xsl:use-attribute-sets="table.cell5">  <fo:block
> xsl:use-attribute-sets="form_data1">
>                                                        <xsl:value-of
> select="format-number(substring-before(UNIT_PRICE,'.'),'#.###','euro2')"/>,
><xsl:if test="(substring(substring-after(UNIT_PRICE,'.'),3,1)) >
> 4"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,'.'),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,'.'),3,1))
> =''"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,'.'),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,'.'),3,1)) =
> 1"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,'.'),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,'.'),3,1)) =
> 2"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,'.'),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,'.'),3,1)) =
> 3"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,'.'),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,'.'),3,1)) =
> 4"><xsl:value-of
> select="(substring(substring-after(UNIT_PRICE,'.'),1,5))"/></xsl:if>
>
> <xsl:if test="(substring(substring-after(UNIT_PRICE,'.'),2,1)) =
> ''"><xsl:value-of
> select="((substring(substring-after(UNIT_PRICE,'.'),1,1))-(substring(substr
>ing-after(UNIT_PRICE,'.'),1,1)))"/></xsl:if>
>
> </fo:block>
>
> </fo:table-cell>
>                                      </fo:table-cell>
>                               </xsl:when>
>                     <xsl:when test="(UNIT_PRICE,1,1 > 1 ) and
> (substring-after(UNIT_PRICE,',') ='') ">
>                                       <fo:table-cell
> xsl:use-decimal-format="euro"> <fo:table-cell
> xsl:use-attribute-sets="table.cell5">  <fo:block
> xsl:use-attribute-sets="form_data1">
>                                       <xsl:value-of
> select="format-number(UNIT_PRICE,'#,###','euro')"/>
>                                               </fo:block>
>                                       </fo:table-cell>
>                                        </fo:table-cell>
>                               </xsl:when>
>
> Thanks,
> Sumir
>
Received on Tuesday, 2 December 2008 18:47:32 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 2 December 2008 18:47:33 GMT