0

案例1(折扣6%):

Subtotal:   750.00
Discount:   45.00
Handling cost:  24.32
21% VAT:    0.00
Total (this is the amount you will deposit):    729.32

案例2(折扣7%):

Subtotal:   1250.00
Discount:   87.50
Handling cost:  39.88
21% VAT:    0.00
Total (this is the amount you will deposit):    1202.38 

我在哪里应用这个公式:

(729.32  - 0.35) / 1.034/ 0.94   =  750.00    (<<--- CORRECT ) ?

(1202.38 - 0.35) / 1.034/ 0.93   = 1250.01    (<<--- My problem why not 1250.00) ?

如何更正 7% 公式以准确获得 1250.00 ?而不是分数错误。

4

2 回答 2

0

我认为这只是浮点运算的 IEEE 标准。有一个工具可以显示,实际发生了什么:

http://www.h-schmidt.net/FloatApplet/IEEE754.html

于 2010-12-26T11:43:40.517 回答
0

知道你从哪里得到你的原始公式,以及你期望每个部分应该做什么真的很有帮助。实际上,我被迫做一些额外的工作,只是为了了解公式中的常数与示例中给出的成本之间的关系。

您的处理成本似乎是根据以下公式计算的:

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 的数字时,仍有百分之一的偏差。

这个小错误来自于我们实际上是在处理四舍五入的数字。当最初计算处理成本和折扣时,它们会四舍五入到最接近的百分之一。这可以被认为是舍入误差。当它们加在一起时,舍入误差会变大。这是处理百分比和价格时的正常副产品。

反向计算时,起始数字(总计)包含舍入误差,最终数字(小计)可以预期接近预期值,但不保证是原始小计。同样,这是由于首次计算总数时的舍入误差和固有的不精确性。

我自己的数学不足以预测和纠正公式中的舍入误差。但是,我确实有关于如何检测它并在事后纠正它的建议。在计算反向小计之后,该数字可用于进行正向计算。如果项目没有按应有的方式加起来,请应用“软糖因素”并重试。根据需要重复。它很乱,而且不是特别优雅,但它应该可以工作。

希望这可以帮助。

于 2010-12-26T12:46:20.713 回答