0
$\begingroup$

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?

  • 0
    6.3 dollars for a banana? Do you mean 6.3¢ ?2012-04-20
  • 0
    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).2012-04-20

1 Answers 1

0

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.

  • 0
    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?2012-04-20
  • 0
    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.2012-04-20
  • 0
    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.2012-04-23
  • 0
    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.2012-04-23