Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding data in XSL to 2 decimal places 1

Status
Not open for further replies.

deepasona

Programmer
Apr 22, 2003
7
0
0
IN
Hi,


<xsl:value-of select=&quot;sum(PersProd/ProductNode/SectionPart/UsageItem/Amount/TaxAmount/Value)&quot;/>)

The output value is
21.599999999999998

How to round it to 2 decimal places

 
i am no xml genie but i think this might be done with a small trick , eg. like this

say var a is the number you now have

try
floor(a*100)/100

or
ceiling(a*100)/100

depending on whether you would rather round up or down.
Hope this helps

kib.at.kibje.com
 
<xsl:value-of select=&quot;floor(sum(PersProd/ProductNode/SectionPart/UsageItem/Amount/TaxAmount/Value)*100)/100)&quot; />

that should do it
 
Using XmlSpy 4.4, it didn't like using '/' as the division operator. I had to use 'div' operator instead. Mine looked like this:

&lt;xsl:value-of select=&quot;floor(sum(PersProd/ProductNode/SectionPart/UsageItem/Amount/TaxAmount/Value)*100) div 100&quot;/&gt;
 
or you can use the function

Code:
<xsl:variable name="number" select="sum(PersProd/ProductNode/SectionPart/UsageItem/Amount/TaxAmount/Value)" />
<xsl:value-of select="format-number($number,'#.##')"/>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top