VBS convert string to floating point

后端 未结 3 1903
广开言路
广开言路 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:07

    Following below procedures can help:

    1. Replacing the dot(".") with comma (",") in the string
    2. change the string to double by Cdbl

    example:

    dim a,b,c
    
    a="10.12"
    
    b="5.05"
    
    a=Replace(a,".",",")
    
    b= Replace(b,".",",")
    
    c=Cdbl(a)+Cdbl(b)
    
    msgbox c
    

提交回复
热议问题