How to split numbers with commas separated using c#

Here is an Example that gives a clear explanation about how to split big integer numbers with commas separated using C# and Data Table



Here is my table, I would like to split update my table's column Records data to commas separated data

Ex:9998 becomes 9,998

My Target :


For getting this what we have to do is :



Here reportData is my table data. there is a method called ToString with one argument is use full for getting our target table , we can convert only integer type data we can not convert string data, if there is a chance to convert our data into integer type then we are able to split the data with commas separated data.

here I am able to convert item["Records"] and item["RecordsLoaded"] into integer type so integer value.(dot) ToString will take an argument for splitting the numbered data but whereas with string value.ToString doesn't take argument so we can not split string data using ToString.

If the number is too long then you can also convert the number to ToDouble... but we need to extends the #s.

item["Records"]=Convert.ToDouble(Records).ToString("###,###,###,###,###");

4 comments: