DataGridView: DefaultCellStyle working with decimals
dataGridViewCellStyle2.Format = "N4";
dataGridView1.DefaultCellStyle= dataGridViewCellStyle2;
When I enter data as 21开发者_开发问答.2134 it displays it properly. But when I enter a complete number like 20, it shows me number as 20.0000. I want to get rid of those trailing 0's.
Edit:
One more issue just encountered. with this code it accepts data as 21.2100.
Please help me to resolve this issue.
Thanks in advance.
VijayYou should try setting the format as
dataGridViewCellStyle2.Format = "0.####";
This will ensure for upto four decimnal points and would be displayed only if values are present
So in your case it should be 21.2134
and just 20
. When you want to access the values use FormattedValue
which will do the formatting as specified for the entered value.
精彩评论