Question

I was just wondering if there was a way to create a custom format in a DataGridViewCellStyle to display data in thousands.

In Excel there is a custom format where you can type 1000 into a cell but it is displayed as 1. I've tried searching these boards but all of my searches return how to insert a thousands separato, which I alread know how to do.

My current workaround is to dividie the data by 1000 before loading the DGV, and then multiplying the user inputs returned back by 1000, but there has to be a better way. I'm dealing with some really large numbers (in Chilean pesos, no less) so I can't show the real number.

No correct solution

OTHER TIPS

Use format string "0,"

From MSDN:

Number scaling specifier: If one or more ',' characters is specified immediately to the left of the explicit or implicit decimal point, the number to be formatted is divided by 1000 each time a number scaling specifier occurs

In RichTextBox this format worked for me:

richTextBox.Text = String.Format("{0:0,}", 24000);//Show as 24

In DataGridView same format can be used in designer or by code:

//Number format "0,.###" will show number 12230 as 12.23

this.datagridview.Columns[this.dgvYuorColumn.Name].DefaultCellStyle.Format = "0,.###";

this is worked for me

this.datagridview.Columns[this.dgvYuorColumn.Name].DefaultCellStyle.Format = "#,#";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top