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.

What's the best way to split the decimal prices and quantities to a whole number representation?

E.g.

100 Banana at $\$$6.3 each, and the seller doesn't accept cents.

I am splitting this using following logic:

Take 6 and immediate next number (7) as prices. So $$6Q_1 + 7Q_2 = 630 ~~\text{ and }~~ Q_1+Q_2=100\cdots$$ Solving this gives me $Q_1=70$ at $\$$6 each and $Q_2=30$ at $\$$7 each.

Is there a better mathematical model to solve this splitting problem accurately for any decimal and quantity?

share|improve this question
    
6.3 dollars for a banana? Do you mean 6.3¢ ? –  anon Apr 20 '12 at 1:18
    
We use dollar signs for $\LaTeX$ (mathematical markup) on MSE. To display an actual dollar sign, one must use $\$$ (the first and last dollar signs are delimeters, and \$ is the markup for a dollar sign). –  anon Apr 20 '12 at 1:24

1 Answer 1

up vote 0 down vote accepted

More generally, you have $n$ bananas at $d$ dollars each, where $nd$ is a whole number. Let $a$ be the greatest integer not exceeding $d$. You propose taking $a$ and $a+1$ as prices, and you are looking for $x$ and $y$ satisfying $$\eqalign{ax+(a+1)y&=nd\cr x+y&=n\cr}$$ This system has the solution $$x=(a+1-d)n,\quad y=(d-a)n$$ This says that $n$ bananas at $d$ dollars each amounts to the same thing as $(a+1-d)n$ bananas at $a$ dollars each and $(d-a)n$ bananas at $a+1$ dollars each.

In your example, you have $n=100,d=6.3$ which yields $a=6$, so 70 at 6 dollars and 30 at 7.

share|improve this answer
    
Agree... but is my assumption to take n and n+1 as prices correct? Or there is any approximation algorithm to solve such a problem in real world? –  Vinay Dwivedi Apr 20 '12 at 3:53
    
It's hard to answer your question, because it's not clear what your question is. It is not clear what makes one solution better than another. What criteria are you using to judge solutions? The method you suggest has the features of using the smallest possible number of different prices, and keeping the prices as close as possible to the average price. If those are important criteria, then you have the best method. I'm not sure what you mean by "approximation algorithm" - I'm giving you formulas, not an algorithm, and an exact answer, not an approximation. –  Gerry Myerson Apr 20 '12 at 4:07
    
kk... I just want to split what ever prices coming up in decimal into whole number.... The solution works great for examples like 100 Bananas @ 6.3... but for example 33 Bananas @ 3.3? In real world, would like to split Options since many exchanges don't accept decimal prices... Thank you. –  Vinay Dwivedi Apr 23 '12 at 3:40
    
33 bananas at 3.3 dollars each comes to 108.9 dollars total, which isn't a whole number, which means an answer like the one in the original question is impossible. You can round it up to 109 dollars, so $d=109/33=3+(10/33)$, and the formulas give 23 bananas at 3 dollars each, 10 bananas at 4 dollars each. –  Gerry Myerson Apr 23 '12 at 4:47

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.