Contrean
Contrean

Reputation: 64

Can't convert a string with a point to a double

I have the problem, that if I try to convert e.g. "10.5" to a double via CDbl(), it becomes 105 instead of 10.5. I searched for an answer for nearly half an hour now and can't find anything. Am I doing a mistake or is it just the way CDbl works?

Private Sub btn_Enter_Click()
    number2 = CDbl(Output)
    Select Case operator
        Case "+"
            Output = number1 + number2
        Case "-"
            Output = number1 - number2
        Case "*"
            Output = number1 * number2
        Case "/"
            Output = number1 / number2
    End Select
    operator = ""
End Sub
number1 = 10
Output (before it gets converted to number2) = "2.5"
operator = "*"

What I should get:
25

What I get:
250

PS: If you wonder why I don't use Application.Evaluate for the operator, my teacher wants me to use a Select Case

Upvotes: 0

Views: 181

Answers (1)

Gustav
Gustav

Reputation: 55841

CDbl assumes the local decimal separator to be present, probably comma in your case.

Use Val when the decimal point is known to be a dot:

number2 = Val(Output)

Upvotes: 3

Related Questions