Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Background: I have a backend system that only accepts prices at an 'each' level with 2 decimal places. IOW you can send a price of 2.99 into the system for an order. But we want to offer dollar off discounts (i.e. $10 off when you spend over 100). So since we can only send a price each (we can't send in total amount at the line item or order level), we need to pro-rate the discount on each line item.

So for example:

item A = (10.26 each x qty of 12) = 123.12 - 10.00 discount = 113.12. 113.12 / 12 = 9.42666666 (we need to get this into a price each with 2 decimals and since we can't over charge customers we round down). So now we have 12 x 9.42 going into the system which is 113.04 and so we just lost 8 cents. Before I hack around this by using something like an adjust item with a price of -8 cents.. is there a proper way to mathematically making this work?

share|improve this question
    
In your example, what if you put $8 \times 9.43$ and also $4 \times 9.42$ into your system. –  littleO Sep 4 '13 at 1:53

1 Answer 1

up vote 0 down vote accepted

In a word, no. You have thrown away the information necessary by rounding down. In your example, there is no way for the system to know whether the correct price is $113.04$ or $113.15$ or anything in between. Because you have a granularity of unit price of $0.01$, when you multiply it by the quantity $n$ you have a granularity $n$ times as big.

If you have regularities in your pricing (all prices end in $.99$, for example) and discounts (always even dollars, for example) in some cases you can recover. But that probably takes more effort than giving the back end the ability to accept more decimals, or the discount separately.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.