Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert a number from string to Integer in vb
How to convert a number from string to Integer in vb

Try it with the following example:

1. Use forced conversion

Dim a as string, i as integer

a="12.53"

i=a

Now the string a is converted into an integer i.

2. Use the type conversion function Cint()

Dim a as string,i as integer

a="12.53"

i=Cint(a)

3. Use the Val() function

This function returns the number contained in the string, which is a numerical value of the appropriate type.

Dim a as string,i as integer

a="12.53"

i=Val(a)

Explanation: here "i=Val(a)" actually uses the function of forced conversion of data types mentioned above. If you change the previous definition to "i as Single", the value output to i will be the single precision of 12.53 Floating point data is not an integer of 13.