Calculation and Round Problem in xForm

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Calculation and Round Problem in xForm

nelsontsang
Hello all,

I have some calculation in the xFrom which used to do the VAT, Totals, etc. in a line item, the code are as follow

--FOR VAT--

  <xforms:setvalue
      ref = "xxforms:repeat-current('repeat_LineItem_model_Trade')/VatValue"
      value = "(xs:double(xxforms:repeat-current('repeat_LineItem_model_Trade')/TotalPrice div 100) * xs:double(xxforms:repeat-current('repeat_LineItem_model_Trade')/VatRate))"
   />

--FOR Line-item Total GROSS PRICE (TotalPriceNID)--

  <xforms:setvalue
     ref = "xxforms:repeat-current('repeat_LineItem_model_Trade')/TotalPriceNID"
     value = "(xs:double(xxforms:repeat-current('repeat_LineItem_model_Trade')/TotalPrice) + xs:double(xxforms:repeat-current('repeat_LineItem_model_Trade')/VatValue))"
  />

However, I found that the code generate a random rounding error on the output, i.e.:

<LineItem>
 <ProductID>101832</ProductID>
  <SellerAssignedID>BB-PL201</SellerAssignedID>
  <Department>0007</Department>
  <Description>Combination Pliers</Description>
  <UOM>6</UOM>
  <BasisQuantity>1</BasisQuantity>
  <PackageQuantity>12</PackageQuantity>
  <ChargeQuantity>12.00</ChargeQuantity>  
  <Amount>6.84</Amount>
  <Discount>0.00</Discount>
  <TotalPriceNID>8.036999999999999</TotalPriceNID>
  <TotalPrice> 6.84</TotalPrice>
  <ExDiscount>6.84</ExDiscount>
  <VatRate>17.50</VatRate>
  <VatValue>1.197</VatValue>
</LineItem>

the TotalPriceNID ( TotalPrice + VatValue) should equals to 8.037 however, Orbeon returns 8.036999999999999. I cannot find any patent how this occur. please refer to my attached file are the extract of one of the output XML files.
Please Notice that
on the line, product = 101832, has the error stated above, however, for product = 101845, the VAT value (TotalPrice * 17.5%) should equal 4.305 not 4.305000000000001 ... etc.

I don't know if it is a bug or anything I have done wrong, please help.
Thanks a lot.

Best regards,
--
Nelson.



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws