-1

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

Ali
  • 33
  • 9
  • There isn't one. Division is a mathematical operation. You divide numbers, not text. You need to convert the `Strings` to an appropriate numeric type. – jmcilhinney Oct 03 '18 at 10:03
  • ` TxOranUst.Text = Math.Round(double.Parse(TxDovizAlisAlt2.Text) / double.Parse(TxDovizAlisAlt1.Text), 4).ToString` ... Welcome to Stack Overflow. A small pointer for you regarding what is off-topic. Questions about how to do something that can be solve with research are generally off-topic. Have a look at this page to explain what `Option Strict` does .. https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/option-strict-statement Don't be put off by down-votes by the way. Everybody gets them :-) – David Wilson Oct 03 '18 at 10:09
  • What format are `TxDovizAlisAlt2.Text1` and `TxDovizAlisAlt1.Text` supposed to be in? integer? single? double? Don't do math on `Strings`. – video.baba Oct 03 '18 at 12:00

1 Answers1

0

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
CruleD
  • 1,153
  • 2
  • 7
  • 15