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
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Tue Jul 01, 2008 4:30 am
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?
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Tue Jul 01, 2008 4:42 am
This?
Code: Select all
$PriceNoTax = $price - ($price * 0.175);
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Tue Jul 01, 2008 4:56 am
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!
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Tue Jul 01, 2008 5:00 am
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.
Eran
DevNet Master
Posts: 3549 Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME
Post
by Eran » Tue Jul 01, 2008 5:01 am
Code: Select all
$priceBeforeVAT = $price * (1 / 1.175);
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Tue Jul 01, 2008 5:03 am
pytrin wrote: Code: Select all
$priceBeforeVAT = $price * (1 / 1.175);
Hey that is cool!