Calculate the chargeback in percentage of the final value C#

Asked

Viewed 45 times

-1

Good evening, the question is more about calculation than programming. The problem is this: if I sell something I must add 15% service charge.

var total = 100;
var acrescimoPercent = 15.00;
var acrescimo = total - (total / 100 * acrescimoPercent); 
total = total + acrescimo; 

Altogether I will have a sale of 115 real, for example. But in case I need to make a chargeback, I can not return the rate of 15%. But now I have 115 and I can not apply the 15% discount why would be less than the original value (97,75), to return to the customer. In short, I need to return the 100 real but I do not know how to apply the percentage for this.

1 answer

2


If you have the formula:

resultado = valor * (1 + juros)

Using your example we would have:

var resultado = 100 * (1 + 0.15)  // resultado = 115

If we have only interest and result and we have no value, just isolate valor in the formula:

resultado = valor * (1 + juros)  // Fórmula inicial
valor * (1 + juros) = resultado  // Invertendo os lados
valor = resultado / (1 + juros)  // Divindo ambos os lados por (1 + juros)

Okay, the final formula is:

valor = resultado / (1 + juros)

In your example it would be

valor = 115 / (1 + 0.15)   // valor = 100
  • I get it, I didn’t do that calculation in the code, just the calculator. But I need to go back to 100, based on the final value 115 and the rate that is 15%. I may have done it wrong but I couldn’t get to the initial result of 100 by following your example. I will try again

  • As I mentioned in the reply, just divide the final value by 1 + porcentagem.. 15% is 0.15.. then just do the calculation 115 / 1.15

  • Dude sorry I messed up I was right. Vlw guy, grateful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.