In Some cases while displaying a large number it will be nice if we can format the number to a more readable format Like : Reputation Point : 537456 Can be more readable if we can write it as Reputation Point : 537,456 ASP.NET provide features like String.Format(format,arg0) to format arguments into different forms.
For above solution you can implement
Response.Write(String.Format("{0:#,###}", 123456789)); Which will print 123,456,789
{0:#,###} → Known as the format string where “{ ,}”are compulsory to mentation. The first part before ‘:’ represent the argument number & it will be an integer.
The second part after ‘:’ represent the format that you want your argument to be converted.
So the above format define we want arg0 to be converted to a comma separated number format.
There are also different number formats available. Some of them listed below:
{0:X} → Convert decimal to hexadecimal. {0:N} → Convert decimal to number format.
{0:C} → Convert number to currency format.
Some of the date formatings and how to use them :
Response.Write("Some Date Pattern"); Response.Write(String.Format(" Short date format: {0:d}", DateTime.Now)); Response.Write(String.Format(" Long date format: {0:D}", DateTime.Now)); Response.Write(String.Format(" Short time format: {0:t}", DateTime.Now)); Response.Write(String.Format(" Long time format: {0:T}", DateTime.Now)); Response.Write(String.Format(" Complete date & short time format: {0:f}", DateTime.Now)); Response.Write(String.Format(" Complete date & long time format: {0:F}", DateTime.Now)); Response.Write(String.Format(" Short date & short time format{0:g}", DateTime.Now)); Response.Write(String.Format(" Long date & long time format{0:G}", DateTime.Now));