Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i wanted to display number with comma in grid view but the problem is the comma is coming after 3 digit i want to display it with using 2 digit.

What I have tried:

Suppose my number is 3317800000 and
i can able to display the result in the format of 3,317,800,000.00 but i want to display the result like 33,17,00,000.00

<asp:BoundField DataField="Number"DataFormatString="{0:N2}" />
Posted
Updated 17-Dec-17 1:40am

1 solution

This code :

double value = 3317800000;
			CultureInfo cInf = (CultureInfo)CultureInfo.InvariantCulture.Clone();
			cInf.NumberFormat.NumberGroupSizes = new int [] {2};
			string V3 = String.Format(cInf.NumberFormat,"{0:00,00.00}", value); 


gives : "33,17,80,00,00.00"

Is it what you want?



This another version (according your demand):
double value = 3317800000;
			CultureInfo cInf = (CultureInfo)CultureInfo.InvariantCulture.Clone();
			cInf.NumberFormat.NumberGroupSizes = new int [] {3,2,2,2};
			string V3 = String.Format(cInf.NumberFormat,"{0:0,0.00}", value); 


gives "3,31,78,00,000.00" - 3 digits before floating point.





Than, add to your bind data class :

CultureInfo cInf = null;
		public string DobleDigitNumber 
		{ 
			get
			{				
				double value = Number;//3317800000;
				if (cInf == null)
				{
					cInf = (CultureInfo)CultureInfo.InvariantCulture.Clone();
					cInf.NumberFormat.NumberGroupSizes = new int[] { 3, 2, 2, 2 };
				}
				return String.Format(cInf.NumberFormat,"{0:0,0.00}", value); 
				
			}		
		}

And change the page code:

		<asp:BoundField DataField="DobleDigitNumber" />
 
Share this answer
 
v3
Comments
AZHAR SAYYAD 18-Dec-17 1:03am    
how can we directly bind in gridview without DobleDigitNumber function
________________ 18-Dec-17 2:48am    
Probably you should give changed CultureInfo to all application, so standard formatting in you application will use changed separations (as you define).
If you need double-digit comma only in one place- best practice is to make it visible and clear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900