westman Posted August 1, 2012 Share Posted August 1, 2012 how do i - 20% of a number in php? i tryed... $my_num = "100";$my_num2 = ($my_num - 20%); but DW is giving an err plus i would like to save the $my_num2 in the format of 0.00 (example 99 - 20% = 79.20) Link to comment Share on other sites More sharing options...
birbal Posted August 1, 2012 Share Posted August 1, 2012 (edited) $num2=$num1-($num1/5); it is just a simple math 20% of $num1 is $num1*20/100 which boils down to above equation (($num1/5)http://php.net/number_format for formating number Edited August 1, 2012 by birbal Link to comment Share on other sites More sharing options...
westman Posted August 1, 2012 Author Share Posted August 1, 2012 i tryed...$my_num = "8";$my_num2 = ($my_num * 20 / 100);and i got 1.6i was looking for 6.4how do i get it write? Link to comment Share on other sites More sharing options...
birbal Posted August 1, 2012 Share Posted August 1, 2012 you need substract the 20% of it from the $my_num1 to get it. what are you geting now is 20% of $my_num1 Link to comment Share on other sites More sharing options...
westman Posted August 1, 2012 Author Share Posted August 1, 2012 (edited) could you give a code demo please Edited August 1, 2012 by westman Link to comment Share on other sites More sharing options...
westman Posted August 1, 2012 Author Share Posted August 1, 2012 got it... $my_num = "8";$my_num2 = ($my_num * 80 / 100); Link to comment Share on other sites More sharing options...
Ingolme Posted August 1, 2012 Share Posted August 1, 2012 You shouldn't have quotation marks around the 8. You're forcing the engine to convert from a string to a number before doing the operation. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 1, 2012 Share Posted August 1, 2012 You can just multiply by .8 also. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now