Question

I have an values like

1,000
25,000
500,000

Need to convert above values as like below without comma

1000
25000
500000

How to acheive this in C#?

how to get reverse output of this -

string.Format("{0:n}", 999999)
Was it helpful?

Solution

You can use the Replace function of the string class like so:

string str = "25,000";
str = str.Replace(",", "");

EDIT:

As suggested by Matthew Watson from the comments

If the string is returned from string.Format("{0:n}", 999999) run on a machine in a locale that uses "." as the thousands separator, this will fail

updated answer:

string num = "25,000";
NumberFormatInfo currentInfo = CultureInfo.CurrentCulture.NumberFormat;
num = num.Replace(currentInfo.NumberGroupSeparator, ""); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top