计算包括银行费用在内的总费用

问题描述

| 你戴上数学帽子了吗? 我正在做一些信用卡处理工作,我需要向客户收取银行服务费,作为便利费。 如果我以$ 100的价格出售某物 并收取我总交易额的3%作为银行服务费。 我总共需要多少费用才能确保我手上仍然有100美元(在银行取走了3%的费用之后) 因此,无论如何,我需要一个可以使用的公式来处理不同的销售额和百分比,以计算出正确的附加费 希望有道理 这是我的第一次尝试,对少量数字有效,但对于大量数字(例如5000美元),这是错误
$surcharge = ($total + ($total * $rate)) * $rate;
这是一个例子,说只需在
$sale = $100
$pct_rate = 0.03; 
$surcharge = $sale * $pct_rate;
$total = $100 + surcharge ; // =103

// test it
$moneyinthehand = 103 - (103 * $rate); // moneyinthehand = $99.91 (which is not $sale price)
    

解决方法

鉴于:
$total_in_hand = 100
$bank_cut_pc = 0.03
我认为这可以满足您的需求:
$to_charge_customer = $total_in_hand / (1.0 - $bank_cut_pc)
数学示例(python):
>>> 100 / (1.0 - 0.03)
103.09278350515464
>>> 103.09278350515464 - (103.09278350515464 * .03)
100.0
    ,
$fee_rate = 3;
$sub_total = 5000;
$surcharge = $sub_total * ($fee_rate / 100);
$total = $sub_total + $surcharge;