Doubt in Calculation of %

Asked

Viewed 2,438 times

1

Could anyone explain to me how to make the following formula? I have 3 values: Valor_Vendido, Valor_Minimo_A_Ser_Vendido and %_Atingida.

Example:

I sold 500 reais and the Valor_Minimo_A_Ser_Vendido it was to be 1000 real, soon I reached 50% in %_atingida.

You don’t have to kiss the code C, I’d just like to know the formula to do the same.

3 answers

7

Rule of three. It’s more a mathematical question than C problem#.

var percentual = (valorVendido * 100) / valorMinino;

4

Decorating formula is complicated, because in a few minutes we will surely forget it.

Better to understand the mechanism, then we’ll never forget how to calculate.

The setup is very simple:

Question

 Se 1000 = 100%, 

    500 = quantos%

Let’s build our equation

   1000     100
 _______ = _______

   500    quantos

Asked the question is just solve the equation.

Since it is a rule of three simple direct, we multiply the values in cross, that is, in X,

inserir a descrição da imagem aqui

how many * 1000 = 500 * 100

how many = (500 * 100)/1000

which in general would be quantos = (valorVendido * 100) / valorMinino;

how many = 50000/1000

how many = 50%

2

Remember, a percentage is a ratio between two values (and therefore one divided by the other) multiplied by 100. Using your example, you soon find out who should be divided by whom; then just multiply by 100. This goes for C# or any programming language.

Browser other questions tagged

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