溫馨提示×

vb如何把字符串轉(zhuǎn)化為數(shù)字

vb
小億
481
2024-02-18 15:30:19
欄目: 編程語言

要將字符串轉(zhuǎn)換為數(shù)字,可以使用Convert.ToInt32()方法來將字符串轉(zhuǎn)換為整數(shù),也可以使用Convert.ToDouble()方法來將字符串轉(zhuǎn)換為浮點(diǎn)數(shù)。示例如下:

Dim str As String = "123"
Dim num As Integer = Convert.ToInt32(str)
Console.WriteLine(num) ' 輸出:123

Dim str2 As String = "3.14"
Dim num2 As Double = Convert.ToDouble(str2)
Console.WriteLine(num2) ' 輸出:3.14

0