How to remove thousand separators using cultureinfo?

I am trying to remove a thousand separators, so I am experimenting with some code, but it throws and throws. I tried with Convert.ToDouble, Convert.ToDecimaletc.

He says:

Convert.ToDouble ("1.234.45") threw and threw a System.FormatException

The conversion is selected from the line: Convert.ToDouble()

The argument n2uses culture info, but I also tried "0.00" and threw the same exception

The whole idea: how to remove a thousand separators, my input is always in this format: 1.234.54 (comma as decimal and dot as thousands separator) ... I like to use it in the GotFocus Event text box .. so the format should be shown as 12345, 45

so: 1.254.45 should be 1254.45 and 1.254.00 should be 1254.00

 //http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

CultureInfo ci = CultureInfo.GetCultureInfo("NL-be");
NumberFormatInfo nfi = (NumberFormatInfo)ci.NumberFormat.Clone();
//Now force thousand separator to be empty string
nfi.NumberGroupSeparator = "";
//Format decimal number to 2 decimal places
string decimalFormatted = Convert.ToDouble("1.234,45").ToString("0.00", nfi);
string decimalFormatted = Convert.ToDouble("1.234,45").ToString("n2", nfi);
+5
2

, :

CultureInfo ci = CultureInfo.GetCultureInfo("NL-be");
double d = Convert.ToDouble("1.234,45", ci);
+6

Convert.ToDouble . , :

string decimalFormatted = Convert.ToDouble("1.234,45").ToString("n2", nfi);

:

double tmp = string decimalFormatted = Convert.ToDouble("1.234,45");
string decimalFormatted = tmp.ToString("n2", nfi);

, , ... .

Double.Parse . ( Convert.ToDouble, t23 .. , TryParse .. , .)

decimal double, . , , decimal, double.

+3

All Articles