How to convert a decimal value of four pleces to decimal value of two places in a gridview



private void dgchkout_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
try
{
if (e.ColumnIndex == 12)
{
if (e.Value == null) return; // nothing entered return

decimal value = Convert.ToDecimal(e.Value); // get the entered value - may throw an exception

e.Value = value.ToString("N2"); // format the entered value

e.FormattingApplied = true;
}
}
catch (Exception ex)
{
log.Trace("CheckOutDet:dgchkout_CellFormatting" + ex.Message);
ex.Data.Clear();
}
}

0 comments:

Template by - Mathew | Mux99