How to format currency string in C# to add commas in thousands place?


I have a string "10000.00", I would like to add commas in thousands place for a give string or number using C# .NET String.Format()? So I can show output as "1,00,00.00", something like this.


Asked by:- neena
0
: 164 At:- 1/21/2020 10:22:07 AM
C# String.Format() add commas asp.net






1 Answers
profileImage Answered by:- bhanu

You can format currency in C# using various methods, here are few

Using Standard Currency formatting in C#

decimal dec = 123.00M;
string ukCurrency = dec.ToString("C", new CultureInfo("en-GB")); // output -> "£123.00"
string usCurrency = dec.ToString("C", new CultureInfo("en-US")); // output -> "$123.00"

Here, "C" (or currency) format specifier converts a number to a string that represents a currency amount.

OR

double price = 1234.25;
string FormattedPrice = price.ToString("N");
//output
// 1,234.25

Here "N"  is used instead of "C".

OR

          var myPrice=110.1211;
		Console.WriteLine(myPrice.ToString("C2")) ;
        Console.WriteLine(myPrice.ToString("N2"));

//output
//$110.12
//110.12

The number after the C and N indicates upto how many decimals you need string formatted.

C formats the number as a currency string, which includes a currency symbol, default symbol is "$', you can use Culture Info as shown above for any other currency type.

OR

                decimal CurrencyAmount = 1000.39m;
		string moneyValue = String.Format("{0:C}", CurrencyAmount);
		
		Console.WriteLine("Formatted value: "+ moneyValue);

               //output : 
               //Formatted value: $1,000.39

OR 

If your Currency value is not a decimal value

string.Format("{0:#.00}", Convert.ToDecimal(CurrencyValue) / 100);

Hope it helps.

2
At:- 1/23/2020 3:25:13 PM
I simply like the first method, and it worked for me, didn't tried other methods, thanks 0
By : neena - at :- 2/13/2020 11:10:39 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use

Subscribe Now

Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly