Rounding Down/Rounding Up

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
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Rounding Down/Rounding Up

Post by Nunners »

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
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Rounding Down/Rounding Up

Post by Jade »

Why don't you just remove rounding, set a number of decimal points you're going to store and then only round when you calculate the final amount?
Post Reply