0

I have very weird problem with adding two values in xsl. XML:

 <BODY>
  <VALUE1>1.21</VALUE1>
  <VALUE2>1.22</VALUE2>
 </BODY>

XSL:

<sum><xsl:value-of select='BODY/VALUE1+BODY/VALUE2'/></sum>

Result:

<sum>2.4299999999999997</sum>

Why result is not 2.43 ? Maybe I should add in another way.

When VALUE1=1.31 and VALUE2=1.23 result is good.

YanTan
  • 1
  • Which processor? – michael.hor257k Dec 30 '21 at 21:45
  • Have you tried to add `1.21 + 1.22` in other programming languages having the same floating point double number representation (e.g. JavaScript)? The result will be the same. If you use an XSLT 2 or 3 processor you can use `xs:decimal` instead of the XPath 1.0 double type e.g. `BODY/VALUE1/xs:decimal(.) + BODY/VALUE2/xs:decimal(.)`. In any case, you can use `format-number where you want to output and format a computational result. – Martin Honnen Dec 30 '21 at 22:00

0 Answers0