VBS convert string to floating point

后端 未结 3 1905
广开言路
广开言路 2021-01-21 10:36
Dim strnumber
strnumber = \"0.3\"

Dim add
add = 0.1

Dim result 
result  = strnumber +  add

MsgBox result

I want to get 0.4 as result, b

3条回答
  •  暖寄归人
    2021-01-21 11:03

    Has to do with your locale settings. Automatic conversion (as well as explicit one) observes it in the same manner as in CStr() function.

    E.g. in my locale CStr( 0.3) results to 0,3 that is invert to CDbl("0,3") while CDbl("0.3") results to an error.

    BTW: always use option explicit and, for debugging purposes, On Error Goto 0

提交回复
热议问题