Assuming I have stored in the database the following
withdraw fee = 2
then upon withdrawing money i want the user to pay 2% for withdrawal fees for any amount he/she is receiving. Given the code below, it only deducts $2 instead of deducting %2 of the balance.
In my code, $postd_cashout is the fees to pay,
balance is the user’s balance
What change should I make to this line for this to work
$postd_cashout = substr(number_format($ir['balance'], 3, '.', ','), 0, -1);
This results in a gross withdrawal of the intended amount plus 2% of that amount. I am unclear if this is exactly what you are trying to achieve, however. The amount the withdrawee receives in hand would be represented in $ir[‘balance’] whereas the gross amount withdrawn is reflected in $postd_cashout.
optionally:
This allows you to change the fee amount anywhere it is referenced in the code as opposed to hardcoding a static number. the intial example is more clear, imho.
finally:
I suppose tracking the fee amount is useful for reporting a sum of fees paid or itemizing a receipt and it sounds like this is ultimately what you’re wanting after re-reading the question a few times. If the fee amount is all you’re after then the other answer fits more elegantly.