Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 978
Totty.js Avatar asked Sep 20 '25 23:09

Totty.js


1 Answers

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
like image 70
Peter Albert Avatar answered Sep 23 '25 05:09

Peter Albert