Calculate percentages in Visual Basic

0

I have a problem trying to calculate a percentage.

I have a form with a maskedtextbox with this format 00% and a textbox to enter a quantity and another to receive the calculation

textbox1       maskedtextbox         resultado      textbox1         textbox2

1000      *         10%         =       100     +     1000      =      1100

The string does not have the correct format:

Dim precio, ganancia, resultado As Double
precio = Convert.ToDouble(txtpreciocompra.Text)
ganancia = Convert.ToDouble(txtganancia.Text) 'txtganancia es el maskedtextbox'
resultado = precio * ganancia / 100 +precio
txtprecioventa.Text = resultado.ToString
    
asked by Samuel Ignacio Susana Confesor 23.07.2017 в 17:13
source

1 answer

-2

at the time of making the calculation is only doing the conversion to double of textbox forgetting that it was actually a maskedtextbox obviously had to exclude literals to work only with the values.

txtganancia.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
ganancia = Convert.ToDouble(txtganancia.Text) / 100
    
answered by 23.07.2017 в 17:44