VBA converts string “12.00” to 1200 instead of 12.00. This happens only on EU regional setting and not US settings

ε祈祈猫儿з 提交于 2019-12-07 18:43:44

问题


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


回答1:


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



回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!