Start a Post

Precision required in ItemBill insert

Partner dazzle
2 Posts

Precision required in ItemBill insert

I have an Item Bill that I am trying to insert nad I am getting the error "Lines[0]" "the line total is unbalanced".


I understand what that means, however,


lines[0].Total = 314.7

lines[0].BillQuantity = 9

lines[0].UnitPrice = 34.97


Now 9 x 34.97 = 314.73 != 314.7


so I have calculated a discount percentage as follows:


lines[0].DiscountPercent = 100 * (lines[0].Total / (lines[0].BillQuantity * line[0].UnitPrice) - 1)


which, in this case, gives -0.0095319797922028405299780800


Working this back through:


lines[0].BillQuantity*lines[0].UnitPrice*(1+lines[0].DiscountPercent/100) = 314.69999999999999999999999999


Now 314.7 != 314.69999999999999999999999999 but it can't get any closer!


The rounding errors are baked into .net. How do I overcome this?



Didn't find your answer here?
Try using advanced search to find a post more easily Advanced Search
Get the conversation started and make a new post Start a Post