Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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|cite|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
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|cite|improve this answer

Your Answer


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.