Page 1 of 1

Trivial maths problem regarding VAT.

Posted: Tue Jul 01, 2008 4:30 am
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?

Re: Trivial maths problem regarding VAT.

Posted: Tue Jul 01, 2008 4:42 am
by Benjamin
This?

Code: Select all

 
$PriceNoTax = $price - ($price * 0.175);
 

Re: Trivial maths problem regarding VAT.

Posted: Tue Jul 01, 2008 4:56 am
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!

Re: Trivial maths problem regarding VAT.

Posted: Tue Jul 01, 2008 5:00 am
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.

Re: Trivial maths problem regarding VAT.

Posted: Tue Jul 01, 2008 5:01 am
by Eran

Code: Select all

 
$priceBeforeVAT = $price * (1 / 1.175);
 

Re: Trivial maths problem regarding VAT.

Posted: Tue Jul 01, 2008 5:03 am
by Benjamin
pytrin wrote:

Code: Select all

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