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

99封情书 提交于 2019-12-06 05:13:51

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