[ic] Rounding and discounts

N.E.S.T. Solutions nest_consulting at yahoo.ca
Mon Jul 23 21:22:13 EDT 2007


> -----Original Message-----
> From: interchange-users-bounces at icdevgroup.org 
> [mailto:interchange-users-bounces at icdevgroup.org] On Behalf 
> Of Jeff Boes
> Sent: Monday, July 23, 2007 5:00 PM
> To: interchange-users at icdevgroup.org
> Subject: [ic] Rounding and discounts
> 
> 
> I have run across a situation that highlights what I think is 
> a problem in the way discounts are applied.
> 
> E.g., if I have a 5% discount for an item that costs $49.50, 
> and the cart contains three items, then the total is
> 
>     ($49.50 * 3) * 0.95 = $141.075, which rounds to $141.07
> 
> That's because the IC code applies the discount to the cart 
> by multiplying the discount by the total cost for each item 
> in the cart (Vend::Interpolate::apply_discount).
> 
> However, this brings up an oddity: if I ask, "what is the 
> discounted price of each item?", the calculation of
> 
>     $141.07 / 3 = $47.025, which rounds to $47.02
> 
> In other words, you get a different answer if you apply the 
> discount to each item's per-item price, round, and then 
> multiply by the quantity, than if you calculate the 
> undiscounted item subtotal, then discount, then round.
> 
> Have others encountered this problem before? Should discounts 
> and rounding be applied in a different way to avoid this?
> 
> -- 
> Jeffery Boes  <><
> jeff at endpoint.com

Hi Jeffery, 

Basic mathematics rules
49.50 * 0.95 = 47.025
49.5 * 3 * 0.95 = 141.075
141.075 / 3 / 0.95 = 49.50 (here you forgot the 95%)

Rounding will offset the total from the exact amounts. The divided
rounded total 
would not give you the exact single item pricing. 
Dividing the rounded total: 141.07 / 3 / 0.95 = 49.49824...

I believe the code is doing things the way it should

Martin H.
N.E.S.T. Solutions




More information about the interchange-users mailing list