Dividing up money?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Dividing up money?

Post by Ward »

I'm currently working on an app that divides up commissions between users. I have a table of percentages, which determines how much each user gets. For example, Let's say someone makes a $100 sale. He gets 80%, another user gets 15%, and another gets 5%. In this example the math is easy, but the tables are much more complicated than that.

I need a way to exactly divide up an amount by percentages. The sum of all pieces must equal the original sale amount. I think my problem lies in the floating point dollar amounts I am winding up with, and some sort of rounding taking place. Any ideas?
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post by Ward »

Well, I found the problem. One of my percentage tables added up to 99.9% instead of 100%. That was causing some the division inaccuracies.
Post Reply