Rounding Down/Rounding Up
Posted: Mon Jan 10, 2011 9:19 am
Before anyone asks, I know how to round up and round down... but it's a bit more of a mathematical problem than that...
I've written a part of our intranet management system that inputs our payroll into the financial database. Each member of staff can work across a number of different departments, and therefore the system allows you to input their total wages, and the hours they have worked in each part... therefore allowing the costs of the staff to be allocated accordingly.
The problem I have is that purely dividing each by the percentage of hours works and rounding up/down then sometimes means that the split total doesn't equal the actual total.... Can anyone think of an easy way to ensure the split is done "correctly" using a straigh tmaths function? Or will I need to write quite a complicated little script to start adding pennies to anything that doesn't add up?!?
Any thoughts gratefully received....
Thanks
Nunners
I've written a part of our intranet management system that inputs our payroll into the financial database. Each member of staff can work across a number of different departments, and therefore the system allows you to input their total wages, and the hours they have worked in each part... therefore allowing the costs of the staff to be allocated accordingly.
The problem I have is that purely dividing each by the percentage of hours works and rounding up/down then sometimes means that the split total doesn't equal the actual total.... Can anyone think of an easy way to ensure the split is done "correctly" using a straigh tmaths function? Or will I need to write quite a complicated little script to start adding pennies to anything that doesn't add up?!?
Any thoughts gratefully received....
Thanks
Nunners