Currency format in a PDF

View: New views
10 Messages — Rating Filter:   Alert me  

Currency format in a PDF

by jlr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How can I include the currency format in a pdf document?
I have the FinalTotal value displayed in the table, but I would
like to have the value formatted in the manner of $XXX,XXX.XX
instead of the plain number value.
Your comments are much appreciated.
CODE BELOW:
         
      <fo:table-body>
        <fo:table-row border-after-style="double" >                  
            <fo:table-cell xsl:use-attribute-sets="cell-padding" border="solid black 0.5px" >  
                <fo:block xsl:use-attribute-sets="detailtableright">    
                   <xsl:value-of select="header/FinalTotal"/>                        
                </fo:block>                          
            </fo:table-cell>    
        </fo:table-row>
      </fo:table-body>
                   
Thank you,
jlr    

Re: Currency format in a PDF

by Roger Roger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


This is handled in XSLT, not XSLFO.

See http://www.w3schools.com/xsl/el_decimal-format.asp

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

    </xsl:stylesheet>

    Output:

    26.825,80

Cheers!

Roger

jlr schreef:

> How can I include the currency format in a pdf document?
> I have the FinalTotal value displayed in the table, but I would
> like to have the value formatted in the manner of $XXX,XXX.XX
> instead of the plain number value.
> Your comments are much appreciated.
> CODE BELOW:
>          
>       <fo:table-body>
>         <fo:table-row border-after-style="double" >                  
>             <fo:table-cell xsl:use-attribute-sets="cell-padding"
> border="solid black 0.5px" >  
>                 <fo:block xsl:use-attribute-sets="detailtableright">    
>                    <xsl:value-of select="header/FinalTotal"/>                        
>                 </fo:block>                          
>             </fo:table-cell>    
>         </fo:table-row>
>       </fo:table-body>
>                    
> Thank you,
> jlr    
>  



Re: Currency format in a PDF

by Tony Graham-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Fri, May 23 2008 14:44:37 +0100, jean.stachler@... wrote:
> How can I include the currency format in a pdf document?
> I have the FinalTotal value displayed in the table, but I would
> like to have the value formatted in the manner of $XXX,XXX.XX
> instead of the plain number value.

You have used format-number() in examples in other posts.  Why not use
it here, too?

Regards,


Tony Graham                         Tony.Graham@...
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


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

by jlr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

First off, thank you for your reply, I have it working.
On to the second question....is there a way of displaying the zero
amounts in a value such as 45.00?  
In the XML file, I see that the value of 45.00, but when it displays it
displays like this 45    .  I would like to display the full value of 45.00.

This is the code that I have:
  <xsl:value-of select="format-number(FinalTotal, '###,###,###.##', 'usdollar')"/>        

Thanks in advance for anyone's comments, it is much appreciated.

jlr    
Tony Graham-3 wrote:
On Fri, May 23 2008 14:44:37 +0100, jean.stachler@crown.com wrote:
> How can I include the currency format in a pdf document?
> I have the FinalTotal value displayed in the table, but I would
> like to have the value formatted in the manner of $XXX,XXX.XX
> instead of the plain number value.

You have used format-number() in examples in other posts.  Why not use
it here, too?

Regards,


Tony Graham                         Tony.Graham@MenteithConsulting.com
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2

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

by Tony Graham-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Fri, May 23 2008 18:33:47 +0100, jean.stachler@... wrote:
...
> In the XML file, I see that the value of 45.00, but when it displays it
> displays like this 45    .  I would like to display the full value of 45.00.
>
> This is the code that I have:
>   <xsl:value-of select="format-number(FinalTotal, '###,###,###.##',
> 'usdollar')"/>        

'###,###,###.00'

or

'###,###,##0.00' (if you want zero to be '0.00')

or

'$###,###,##0.00' (if you want zero to be '$0.00')

Regards,


Tony Graham                         Tony.Graham@...
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


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

by Chawla :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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(substring-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(substring-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

First off, thank you for your reply, I have it working.
On to the second question....is there a way of displaying the zero
amounts in a value such as 45.00?  
In the XML file, I see that the value of 45.00, but when it displays it
displays like this 45    .  I would like to display the full value of 45.00.

This is the code that I have:
  <xsl:value-of select="format-number(FinalTotal, '###,###,###.##', 'usdollar')"/>        

Thanks in advance for anyone's comments, it is much appreciated.

jlr    
Tony Graham-3 wrote:
On Fri, May 23 2008 14:44:37 +0100, jean.stachler@crown.com wrote:
> How can I include the currency format in a pdf document?
> I have the FinalTotal value displayed in the table, but I would
> like to have the value formatted in the manner of $XXX,XXX.XX
> instead of the plain number value.

You have used format-number() in examples in other posts.  Why not use
it here, too?

Regards,


Tony Graham                         Tony.Graham@MenteithConsulting.com
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


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

by dahepe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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
>


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

by Chawla :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

What i want is if unit price is coming as ,33 or .33 in the output, instead it should come 0,33 or 0.33 in the output. How can I pad 0 before , or . ?

Regards,
Sumir
dahepe wrote:
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
>

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

by Chawla :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

My code which is responsible for displaying unti price is given below :
<fo:table-cell><fo:block></fo:block></fo:table-cell>
<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>

So, I have to manipulate this code in such a way that instead of displaying ,45 or .45, it should display 0,45 or 0.45 but 0 should not be appended in case when unit price is like 1.26 or 3.45..etc etc. How can I incorporate this condition in the above code?

Regards,
Sumir

Hi,

What i want is if unit price is coming as ,33 or .33 in the output, instead it should come 0,33 or 0.33 in the output. How can I pad 0 before , or . ?

Regards,
Sumir
dahepe wrote:
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
>


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

by dahepe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

> So, I have to manipulate this code in such a way that instead of displaying ,45 or .45,
> it should display 0,45 or 0.45 but 0 should not be appended in case when unit price
> is like 1.26 or 3.45..etc etc. How can incorporate this condition in the above code?

Try to use the following instructions to format the number is the way you described (note that the decimal format must be declared only once!!):

<xsl:decimal-format name="us" decimal-separator="." grouping-separator=","/>
...
<xsl:value-of select="format-number(put-your-number-here, '#,##0.00', 'us')"/>

Perhaps you should have a look at the documentation of the decimal-format, format-number (http://www.w3.org/TR/xslt#function-format-number) and syntax of the format string (http://java.sun.com/javase/6/docs/api/java/text/DecimalFormat.html) to know what you are doing...

Regards,
Daniel