Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 除法运算符始终返回整数_Vb.net_Visual Studio - Fatal编程技术网

Vb.net 除法运算符始终返回整数

Vb.net 除法运算符始终返回整数,vb.net,visual-studio,Vb.net,Visual Studio,我正在编写一个Windows窗体应用程序。使用变量Dim secnumber查看此代码的后半部分。当我运行代码并给它一个像5或3这样的值时,它只会四舍五入到一个整数,我希望它是十进制的。我不知道我做错了什么 'Declare variable Dim number As Integer 'Extract the number from the text box Dim intnumber = Convert.ToInt32(txtintbox.Text)

我正在编写一个Windows窗体应用程序。使用变量
Dim secnumber
查看此代码的后半部分。当我运行代码并给它一个像
5
3
这样的值时,它只会四舍五入到一个整数,我希望它是十进制的。我不知道我做错了什么

    'Declare variable
    Dim number As Integer

    'Extract the number from the text box
    Dim intnumber = Convert.ToInt32(txtintbox.Text)

    'Calculate to double the number
    number = intnumber * 2

    'Convert the number to display in message box
    MessageBox.Show("When the number is doubled, the result is: " & number)

    'Clear the text box
    txtintbox.Text = ""

End Sub

Private Sub halfbtn_Click(sender As Object, e As EventArgs) Handles halfbtn.Click




    'Declare variable
    Dim secnumber As Double

    'use th number from the text box
    secnumber = Convert.ToInt32(txtintbox.Text)

    'Calculate the number by half
    secnumber = secnumber \ 2

    'Convert number to display the result in message box
    MessageBox.Show("Half of this number is: " & secnumber)

    'Clear the text box
    txtintbox.Text = ""


End Sub

secnumber=secnumber\2
更改为
secnumber=secnumber/2

/是标准部门吗 \是整数除法


欢迎使用堆栈溢出!请审阅:并更新您的问题标题和详细信息。谢谢!