chinwan Posted July 27, 2009 Share Posted July 27, 2009 I have a script that is calculating how much the credit card fee was to process a payment. I am going to be use relatively fixed values for the credit card percent. As of now, I have the percent written as a decimal point (".275") , but I would rather have it as a "2.75%". How would I restructure my statement: $creditcardpercent = ".275" $balance = $order * $creditcardpercent That it will calculate it properly? Thanks Link to comment https://forums.phpfreaks.com/topic/167568-curently-using-decimal-point-for-percent-how-can-i-use-the-percent-sign/ Share on other sites More sharing options...
vineld Posted July 27, 2009 Share Posted July 27, 2009 Where do you have it written with decimal point? In the database? I guess you mean 27.5% and not 2.75 in this case? Link to comment https://forums.phpfreaks.com/topic/167568-curently-using-decimal-point-for-percent-how-can-i-use-the-percent-sign/#findComment-883653 Share on other sites More sharing options...
abazoskib Posted July 27, 2009 Share Posted July 27, 2009 multiply the decimal number by 100. this will give you a percent figure i.e. $number = .376; $percent = $number*100; echo $percent."%"; //display 37.6% Link to comment https://forums.phpfreaks.com/topic/167568-curently-using-decimal-point-for-percent-how-can-i-use-the-percent-sign/#findComment-883656 Share on other sites More sharing options...
vineld Posted July 27, 2009 Share Posted July 27, 2009 Then you will have to adjust your calculations though so that you don't multiply with the number of percents. That will get expensive Link to comment https://forums.phpfreaks.com/topic/167568-curently-using-decimal-point-for-percent-how-can-i-use-the-percent-sign/#findComment-883659 Share on other sites More sharing options...
Philip Posted July 27, 2009 Share Posted July 27, 2009 You cannot use like $per = 5.35% because the per cent sign is a modulus operator. $creditcardpercent = .275 *100; $balance = $order * $creditcardpercent; // or $creditcardpercent = .275; $balance = $order * ($creditcardpercent * 100); Link to comment https://forums.phpfreaks.com/topic/167568-curently-using-decimal-point-for-percent-how-can-i-use-the-percent-sign/#findComment-883661 Share on other sites More sharing options...
vineld Posted July 27, 2009 Share Posted July 27, 2009 Perhaps I misunderstood you. Of course you not user "2.75%" in calculations and you must not store the value that way in the database but you may display if on your pages in any format you wish. Whether you store it as 2.75 or 0.0275 doesn't really matter, you can do format them in anyway you like when producing html output. Link to comment https://forums.phpfreaks.com/topic/167568-curently-using-decimal-point-for-percent-how-can-i-use-the-percent-sign/#findComment-883669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.