数据样本:20.50和20.00总计:41.00
我怎样才能得到准确的数字40.50?我可以对列进行汇总并显示在标签中,但是我无法解决舍入问题。
If DataGridView1.RowCount > 1 Then
Dim tutar As Integer = 0
For index As Integer = 0 To DataGridView1.RowCount - 1
total += Convert.ToInt32(DataGridView1.Rows(index).Cells(3).Value)
Next
Label1.Text = total.ToString("N2")
End If
我假设变量total
是an Integer
,请尝试将total
变量更改为type Double
。
您代码中的某处..
Dim total As Double = 0
然后更改此:
If DataGridView1.RowCount > 1 Then
Dim tutar As Integer = 0
For index As Integer = 0 To DataGridView1.RowCount - 1
total += Convert.ToDouble(DataGridView1.Rows(index).Cells(3).Value.tostring)
Next
Label1.Text = total.ToString()
End If
如果您想四舍五入,请点击此链接
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句