I don't know why but the string in vba is "12.00" and when I conver to a double with
myDouble= CDbl(stringDouble)
or
myDouble = stringDouble
I cannot do anything.. any help? (I cannot change the regional settings to US on all pcs..)
thanks
As you already noted in your comments, this is a regional setting - as your system is using ,
as the decimal separator, the string gets converted to 1200
. The solution in this case is to convert it with Val
:
Sub Sample()
Dim myDouble As Double
Dim stringDouble As String
stringDouble = "12.00"
myDouble = Val(stringDouble)
End Sub
This is most likely due to regional settings - decimal separator differs. E.g. in my locale it's ,
- that's why for string-to-number conversion I use such syntax:
x = "12.00"
DBLnum = CDbl(Replace(x, ".", ","))
来源:https://stackoverflow.com/questions/14979333/vba-converts-string-12-00-to-1200-instead-of-12-00-this-happens-only-on-eu-re