我正在编写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
答案 0 :(得分:2)
将secnumber = secnumber \ 2
更改为secnumber = secnumber / 2
/是标准部门 \是整数除法