How to calculate +10.5% in a product

Asked

Viewed 80 times

0

How to calculate +10.5% in a product?

My calculus is like this:

private void txtMargemLucro_Leave(object sender, EventArgs e)
{
    txtPrecoVenda.Text = (Convert.ToDecimal(txtPrecoCusto.Text) * 
                          Convert.ToDecimal(txtMargemLucro.Text) / 100 +    
                          Convert.ToDecimal(txtPrecoCusto.Text)).ToString();
}

This method puts masks on the txtPrecoVenda that receives result and this formatted

public void Moeda(ref TextBox txt)
{
    string n = string.Empty;
    decimal v = 0;
    try
    {
        n = txt.Text.Replace(",", "").Replace(".", "");
        if (n.Equals(""))
            n = "";
        n = n.PadLeft(3, '0');
        if (n.Length > 3 & n.Substring(0, 1) == "0")
            n = n.Substring(1, n.Length - 1);
        v = Convert.ToDecimal(n) / 100;
        txt.Text = string.Format("{0:N}", v);
        txt.SelectionStart = txt.Text.Length;
    }
    catch (Exception)
    {
        throw;
    }
}

the value returns correct if it is integer value 15%, but if it’s 10.5% it’s a mistake.

  • In practice, what does "give error" mean? It would be good to [Dit] the question and better explain what was the result obtained, and what you expected as correct.

  • If you divide by 1000 and multiply by 105, it would be equivalent.

  • 1

    What is the purpose of if (n.Equals("")) n = "";?

No answers

Browser other questions tagged

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