0

Imagine that: I have a small financial value to divide in several costs accounts.

For example: I have $0.36 of something cost to divide equally on my 40 subsidiaries, and my smallest value I can register to one subsidiary is $0.01.

Looking to the problem is simple: 36 subsidiaries will have $0.01 of cost registered, and 4 of my subsidiaries won't have that cost, right?

Is there a known or common algorithm to resolve that? (that kind of algorithm that have a fancy name :) )

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Is this going to be done incrementally several times, and you want to make sure that no one gets penalized unfairly often? – Jerry Federspiel Aug 06 '15 at 19:43
  • 1
    Why is $0.01 your resolution? If you're doing this kind of distribution, you should go to mills or millrays. And yes, you should use integer type values for financial quantities, but keep it integer amount of millrays. – mpez0 Aug 06 '15 at 19:44
  • 1
    No algorithmic solution to that one, I'm afraid - you'll just have to hit each subsidiary with a $0.01 cost and then introduce a separate account for holding the rounding errors so that your total stays correct :) – 500 - Internal Server Error Aug 06 '15 at 19:48
  • When you say "algorithm to resolve that" - what would you do if it was *you* doing this, rather than a computer? Decide that first. Getting the computer to do it is the easy bit! – AakashM Aug 07 '15 at 08:41

1 Answers1

0

I see 2 solutions: 1. Use money type or equivalent (many frameworks contains it) 2. Use fractions like A/B. For example, you need to devide 0.36 on 40 members. So, every will get 0.36/40 or 9/10. And store this as two values 9 and 10. Then, use fraction arithmetic

Backs
  • 24,430
  • 5
  • 58
  • 85