Trivial maths problem regarding VAT.

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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Trivial maths problem regarding VAT.

Post by onion2k »

I have a price. It includes tax. I need to get the price before tax. (The tax rate is always 17.5%)

Code: Select all

$price + ( $price - ( $price * 1.14896 ) )
That gets the right value, but can the maths be written in a simpler way?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Trivial maths problem regarding VAT.

Post by Benjamin »

This?

Code: Select all

 
$PriceNoTax = $price - ($price * 0.175);
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Trivial maths problem regarding VAT.

Post by onion2k »

I wish it was that simple..

100*1.175 = 117.5
117.5-(117.5*0.175) = 96.93

I need to go from 117.5 back to 100. That's a reduction of 14.8936%.

Actually.. thinking about it..

117.5-(117.5*0.148936)

That works and it's a bit simpler than my first attempt. Yay!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Trivial maths problem regarding VAT.

Post by Benjamin »

Yeah that is probably the best solution. I would put 0.148936 into a constant as I'd probably need it in more than once place.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Trivial maths problem regarding VAT.

Post by Eran »

Code: Select all

 
$priceBeforeVAT = $price * (1 / 1.175);
 
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Trivial maths problem regarding VAT.

Post by Benjamin »

pytrin wrote:

Code: Select all

 
$priceBeforeVAT = $price * (1 / 1.175);
 
Hey that is cool!
Post Reply