Search code examples
vb.netdoubletype-conversiontryparse

dividing 2 doubles results always in 1 vb


both txtfield1 and txtMCLCCurrToEUR are doubles

(originally strings converted to double, both are the values of forex with 5 digits after decimal point)

Dim f1 As Double
txtField2.Text = (Double.TryParse(txtMCLCurrToEUR.Text, f1) / Double.TryParse(txtField1.Text, f1)).ToString("N5")

irrespective of their values, I always end up with 1 in the txtField2.text

I seem to have overlooked something essential, but for the life of me -- I don't see what it could be...

any help would be much appreciated!


Solution

  • You should not use f1 for both conversions, the second one would overwrite the first and the result is always one. Tryparse has no return value, only a flac vor succeed or not.

    Dim f1 As Double
     Double.TryParse(txtMCLCurrToEUR.Text, f1)
    Dim f2 As Double
     Double.TryParse(txtField1.Text, f2)
    txtField2.Text =  (f1/f2 ).ToString("N5")