sqlserver表中的金额是 numeric(18,6)
datagridview中显示的数字是 [342.260000、123.000000、43.300000],自己都觉得很难看,
不知在不更改sql查询语句的前提下怎么对网格中的数字列进行格式化,去掉后果面多余的零。sql查询中处理是很简单的:select replace(rtrim(replace(AMT,'0',' ')),' ','0'), * from SoOrdDtl
datagridview中显示的数字是 [342.260000、123.000000、43.300000],自己都觉得很难看,
不知在不更改sql查询语句的前提下怎么对网格中的数字列进行格式化,去掉后果面多余的零。sql查询中处理是很简单的:select replace(rtrim(replace(AMT,'0',' ')),' ','0'), * from SoOrdDtl
DataGridView.Columns[?].DefaultCellStyle.Format
' 单元格式化2位小数.
Private Sub DataGView_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGView.CellFormatting
If DataGView.Columns(e.ColumnIndex).HeaderText = "毛重"
If (e.Value) IsNot DBNull.Value Then
e.Value = FormatNumber(e.Value, 2, , , TriState.True)
End If End If
End Sub
'==============================
'或者:“编辑列”中,在绑定列属性中, “外观”中选 DefaultCellStyle , 点中Format,旁边有个按钮,点中后可设置各种格式,比如2位小数等。
'======================================================
'或者在程序中: DataGridView1.Columns(6).DefaultCellStyle.Format = "N2"
以前试过“.DefaultCellStyle.Format="###.###.##0.######"”对 select AMT from SoOrdDtl 无效,
但对 select sum(AMT) as AMT from SoOrdDtl 有效,不知什么原因。@3楼:“.DefaultCellStyle.Format = "N2"”与2楼相同。