How to calculate + 10.5% in a product

0

How to calculate + 10.5% on a product?

My calculation looks 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 txtPrecoVenda that receives result and is 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 is 10.5% it gives error.

    
asked by anonymous 22.08.2016 / 07:22

0 answers