title: Applying multiple percentages simultaneously
body: <p>I have a source value that I need to apply multiple percentages, but at the same time, and the percentages have to take into account the other percentages.</p>
  
  <p>Take for instance:<br />
  Value = 100<br />
  Percentage1 = 10%<br />
  Percentage2 = 15%<br />
  Percentage3 = 17%</p>
  
  <p>I need to work out what the final value would be, but when adding Percentage1 it has to take into account the values from Percentage2 and Percentage3.</p>
  
  <p>The only way I have managed this at the moment is to recursively calculate the value with the last values of the other percentages until there are no more changes, but I'm not even sure if that is right.</p>
  
  <p>Is there a smarter way of calculating this?</p>
  
  <p>EDIT: This is basically to calculate multiple fees.
  So say you put up a listing on eBay and you get charged 10% for listing on eBay, and the buyer has bought through paypal, and you get charged 15% for a paypal transaction, and then you get charged a further 17% due to shipping, we are trying to work out what the final fees will be and then scale the value accordingly.</p>
  
  <p>This is the code that I'm using:</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>This is my recursive list, so you start with the initial value of 100, and then use the previous values of the other fees until there are no more changes (rounded to 4 decimal places)</p>
  
  <pre><code>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
  </code></pre>
  
  <p>So in this case my final sum is 157.8888</p>