vb.net 不断去掉等式中的小数
vb.net keeps removing decimal in equation
我有一个变量,其值归结为一个使用小数位的数字。示例 257.85 然而,当我在以下等式中进一步处理该值时,它会删除小数点,数字变为 25785,这是不正确的。
vb.net中使用的等式:
Dim ITEM2b As Integer = DataGridView1.Item(2, 0).Value '<--This case senario the value came to 257.85
Dim ITEM15 As Integer
If item1B = 4 Then
ITEM15 = ((ITEM2b / 10) - (ITEM5b / 10)) / 2
ElseIf item1B = 3 Then
ITEM15 = ((ITEM2b / 10) - (ITEM5b / 10)) / 3
'MsgBox(ITEM2b & " " & ITEM5b) '<-- This line helped reveal the problem
'ITEM15 = ((257.85 / 10) - (50 / 10)) / 3
ElseIf item1B = 2 Then
ITEM15 = ((ITEM2b / 10) - (ITEM5b / 10)) / 2
End If
我尝试将 Item2b 变量设置为 Integer、string 和 Double,但都无济于事!
Dim ITEM2b As Integer = DataGridView1.Item(2, 0).Value '<--This case senario the value came to 257.85
Dim ITEM15 As Integer
您将值传递给一个整数,这将导致该值删除其小数位。
尝试使用 Double。
Dim ITEM2b As Double= DataGridView1.Item(2, 0).Value '<--This case senario the value came to 257.85
Dim ITEM15 As Double
我有一个变量,其值归结为一个使用小数位的数字。示例 257.85 然而,当我在以下等式中进一步处理该值时,它会删除小数点,数字变为 25785,这是不正确的。
vb.net中使用的等式:
Dim ITEM2b As Integer = DataGridView1.Item(2, 0).Value '<--This case senario the value came to 257.85
Dim ITEM15 As Integer
If item1B = 4 Then
ITEM15 = ((ITEM2b / 10) - (ITEM5b / 10)) / 2
ElseIf item1B = 3 Then
ITEM15 = ((ITEM2b / 10) - (ITEM5b / 10)) / 3
'MsgBox(ITEM2b & " " & ITEM5b) '<-- This line helped reveal the problem
'ITEM15 = ((257.85 / 10) - (50 / 10)) / 3
ElseIf item1B = 2 Then
ITEM15 = ((ITEM2b / 10) - (ITEM5b / 10)) / 2
End If
我尝试将 Item2b 变量设置为 Integer、string 和 Double,但都无济于事!
Dim ITEM2b As Integer = DataGridView1.Item(2, 0).Value '<--This case senario the value came to 257.85
Dim ITEM15 As Integer
您将值传递给一个整数,这将导致该值删除其小数位。
尝试使用 Double。
Dim ITEM2b As Double= DataGridView1.Item(2, 0).Value '<--This case senario the value came to 257.85
Dim ITEM15 As Double