複数のパーセンテージを適用する必要があるソース値がありますが、同時に、パーセンテージは他のパーセンテージを考慮に入れる必要があります。
たとえば、
値= 100
Percentage1 = 10%
Percentage2 = 15%
Percentage3 = 17%
最終的な値を計算する必要がありますが、Percentage1を追加するときは、Percentage2とPercentage3の値を考慮に入れる必要があります。
現時点でこれを管理している唯一の方法は、変更がなくなるまで他のパーセンテージの最後の値を使用して値を再帰的に計算することですが、それが正しいかどうかさえわかりません。
これを計算するより賢い方法はありますか?
編集:これは基本的に複数の料金を計算するためのものです。たとえば、eBayに出品し、eBayに出品すると10%が請求され、購入者がペイパルを通じて購入し、ペイパル取引に対して15%が請求され、さらに17%が請求されるとします。輸送、我々は最終的な料金が何であるかを計算して、それからそれに応じて価値をスケーリングしようとしています。
これは私が使用しているコードです:
Dim Value As Decimal = 100
Dim Fee1Percent As Decimal = 0.1
Dim Fee2Percent As Decimal = 0.15
Dim Fee3Percent As Decimal = 0.17
Dim PreviousFee1 As Decimal
Dim PreviousFee2 As Decimal
Dim PreviousFee3 As Decimal
Dim Fee1 As Decimal
Dim Fee2 As Decimal
Dim Fee3 As Decimal
Do
PreviousFee1 = Fee1
PreviousFee2 = Fee2
PreviousFee3 = Fee3
Fee1 = Math.Round((Value + PreviousFee2 + PreviousFee3) * Fee1Percent, 4, MidpointRounding.AwayFromZero)
Fee2 = Math.Round((Value + PreviousFee1 + PreviousFee3) * Fee2Percent, 4, MidpointRounding.AwayFromZero)
Fee3 = Math.Round((Value + PreviousFee1 + PreviousFee2) * Fee3Percent, 4, MidpointRounding.AwayFromZero)
Loop Until PreviousFee1 = Fee1 AndAlso PreviousFee2 = Fee2 AndAlso PreviousFee3 = Fee3
これは私の再帰リストなので、初期値100から始めて、変更がなくなるまで(小数点以下第4位に四捨五入)他の料金の以前の値を使用します。
10.0 15.00 17.00
13.200 19.0500 21.2500
14.0300 20.1675 22.4825
14.2650 20.4769 22.8136
14.3291 20.5618 22.9061
14.3468 20.5853 22.9315
14.3517 20.5917 22.9385
14.3530 20.5935 22.9404
14.3534 20.5940 22.9409
14.3535 20.5941 22.9411
14.3535 20.5942 22.9411
14.3535 20.5942 22.9411
したがって、この場合、私の最終的な合計は157.8888です。