知道你从哪里得到你的原始公式,以及你期望每个部分应该做什么真的很有帮助。实际上,我被迫做一些额外的工作,只是为了了解公式中的常数与示例中给出的成本之间的关系。
您的处理成本似乎是根据以下公式计算的:
0.35 + (subtotal - discount) * 0.034
我不知道为什么 0.35 存在。
您的折扣似乎是根据以下公式计算的:
subtotal * discount rate, (where discount rate has already been converted to a decimal)
总数似乎是根据以下公式计算的:
subtotal + handling costs - discount
写完这篇文章,再加上一些思考,我猜你想在只知道费率和小计的情况下进行反向计算来确定小计。让我们从我们所知道的开始,然后根据需要重新排列公式。
subtotal = total + discount - handling costs
subtotal = total + subtotal * discount rate - (0.35 + (subtotal - discount) * 0.034)
subtotal (1 - discount rate) = total - (0.35 + subtotal - subtotal * discount rate) * 0.034
subtotal (1 - discount rate) = total - 0.35 - subtotal (1 - discount rate) * 0.034
subtotal (1 - discount rate) + subtotal (1 - discount rate) * 0.034 = total - 0.35
subtotal (1 - discount rate) (1 + 0.034) = total - 0.35
subtotal (1 - discount rate) * 1.034) = total - 0.35
subtotal = (total - 0.35) / ((1 - discount rate) * (1.034))
所以好消息是我已经提出了和你一样的数学方程,现在大部分情况下你都明白了你是如何得出它的。坏消息是,在输入案例 #2 的数字时,仍有百分之一的偏差。
这个小错误来自于我们实际上是在处理四舍五入的数字。当最初计算处理成本和折扣时,它们会四舍五入到最接近的百分之一。这可以被认为是舍入误差。当它们加在一起时,舍入误差会变大。这是处理百分比和价格时的正常副产品。
反向计算时,起始数字(总计)包含舍入误差,最终数字(小计)可以预期接近预期值,但不保证是原始小计。同样,这是由于首次计算总数时的舍入误差和固有的不精确性。
我自己的数学不足以预测和纠正公式中的舍入误差。但是,我确实有关于如何检测它并在事后纠正它的建议。在计算反向小计之后,该数字可用于进行正向计算。如果项目没有按应有的方式加起来,请应用“软糖因素”并重试。根据需要重复。它很乱,而且不是特别优雅,但它应该可以工作。
希望这可以帮助。