Categories

Tools

bitdefender

1&1 Web Hosting

Use String.Format ( ) in ASP.NET to format text or currency or numbers


string message = String.Empty;

string name = "Bill";

string[] type = { "Balance", "Credit", "Debt" };

double value = 7385556.71d;

int days = 134;

message += String.Format("Hello {0},<br />Your {1} is {2:C}, <br />Your last login was done {3:G} days ago", name, type[1], value, days);

LiteralMessage.Text = message;

 

The result:

Hello Bill,
Your Credit is $7,385,556.71,
Your last login was done 134 days ago

This example uses {2: C} to format value as Currency and {3: G} to format days which is an integer value as General, without commas or dots

Posted in ASP.NET by MdmSoft

If our work has been of help, you can help us with a small donation...
Our programmers will thank you!



All information contained in this web site are the property of MdmSoft. The information is provided "as is", MdmSoft will not be liable for any misuse of the code contained in these pages, nor can it be for inaccuracies, grammatical errors or other factors that may have caused damage or lost earnings. MdmSoft is not responsible for the content of comments posted by users.
The examples in this area have the educational and demonstration purposes only, and may be copied only for your reference, but cannot be used for commercial purposes, or for any other purpose, without the express written consent of MdmSoft.
MdmSoft also reserves the right to change, without notice, to your liking this web site, the pages and its sections, and may suspend temporarily or definitely the various services included on this site.
While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy.