« Return to Thread: Currency format in a PDF

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

by Chawla :: Rate this Message:

Reply to Author | View in Thread

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

 « Return to Thread: Currency format in a PDF