Search code examples
stringvb.netdecimaldivide-by-zerooption-strict

Dividing two text string with option strict on


Can you please help me to get the best method for dividing two text string with option strict on

  If TxDovizAlisAlt1.Text <> "" Then

        TxOranUst.Text = Math.Round(TxDovizAlisAlt2.Text / TxDovizAlisAlt1.Text, 4)
    End If

Text string are retrieving from a web page either with "." or "," decimal sembol


Solution

  • Since you have text (string) inside textbox, you first have to convert that text to actual number.

    Without knowing what the actual data is in them I'll be vague and say that you can use something like TryParse, Cast or Convert.

    For example:

    Math.Round(CDbl(TxDovizAlisAlt2.Text) / CDbl(TxDovizAlisAlt1.Text), 4)
    
    Dim test As Double = Math.Round(CDbl("123.456") / CDbl("78.910"), 4)
    Debug.Print(test.ToString) 'Print>>> 1.5645