Web Hosting Talk







View Full Version : php calculate percentage


lexington
04-30-2009, 05:40 AM
Wow, I thought this would be extremely easy, but I am trying to do something different than what just about every php percentage example on the net offers. Every example I have searched for only displays the percent from a total. I want to know the total after the percentage is applied. I know how to do this on the calculator but do not know how to do it with php. So like if the value is 2296 at 26%, the result should be 596.96 (2296 X 26% = 596.96). I am using this to calculate taxes. Could you please provide me with a working example that will display the amount? I bet it is easy, and since I haven't been to sleep yet my brain is dead now. Thanks.

plumsauce
04-30-2009, 05:45 AM
And this is why calculators should not be allowed before having learned the paper method.

You have two choices.

gross it up right away

or, calculate and add.

And don't forget rounding effects.

lexington
04-30-2009, 05:53 AM
Thanks, I figured it out. Even with round() or ceil() the amount is a dollar off, but hopefully it is no more than a dollar off every time. I used this and it works:

$tax_estimate = ($total / 100) * 26;
ceil($tax_estimate);

shackrat
04-30-2009, 11:21 AM
Make it nice and neat with 2 decimal places...


$tax_estimate = round(($total*.26), 2);