Interviews7 answers
How to Format a String as Currency?
7 Answers
decimal moneyvalue = 1921.39m;
string html = String.Format("Order Total: {0:C}", moneyvalue);
Console.WriteLine(html);
Sujeet SinghPosted Jul 22, 2018, 9:22 AM EDT
string.Format("{0:#.00}", Convert.ToDecimal(myMoneyString) / 100);
Rajkiran SwainPosted Jun 7, 2017, 3:11 AM EDT
decimal moneyvalue = 1921.39m;
string html = String.Format("Order Total: {0:C}", moneyvalue);
Console.WriteLine(html);
Raj KumarPosted Jun 6, 2017, 12:27 PM EDT
When building a string for output to a web page, it’s useful to format any currency value in a human-friendly money format. This is extremely easy in C#.
The system format string works like this: {0:C}
For example, the following code example:
decimal moneyvalue = 1921.39m;
string html = String.Format("Order Total: {0:C}", moneyvalue);
Console.WriteLine(html);
Outputs the following:
Order Total: $1,921.39
It’s worth noting that you must pass in a numeric value to the String.Format statement. If you pass in a string value, it won’t format correctly. If your currency value is in a string, you need to convert it into a double first.
Raj KumarPosted Jun 6, 2017, 12:26 PM EDT
double dblAmt=134600.00;
System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfo("en-IN");
string StrAmt = dblAmt.ToString("N2", info);
txtAmt.Text = StrAmt;
Output := 1,34,600.00
Chetan RaiyaniPosted Jun 5, 2017, 3:42 AM EDT
double dblAmt=134600.00;
System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfo("en-IN");
string StrAmt = dblAmt.ToString("N2", info);
txtAmt.Text = StrAmt;
Output := 1,34,600.00
Chetan RaiyaniPosted Jun 5, 2017, 3:42 AM EDT
The standard numeric format specifier we use is the Currency (“C”) Format specifier, which is
formatted like this: { 0:C }
decimal value = 1234.88m;string ttl = string.Format("{ 0:C }", value);
WriteLine(ttl + " \n\n");
In other way we can achieve the same result is by using ToString() function.
Ex:
decimal value = 1234.88m;
WriteLine(value.ToString("C") + " \n\n");
ReadKey();
Using CultureInfo.CreateSpecificCulture() one can set the culture information, and thereby adjust to the country and print out the price with the proper money currency symbol.
Santosh Kumar AdidawarpuPosted Feb 10, 2017, 9:44 PM EST



