Quantcast
Channel: how to remove the thousand separator using cultureinfo? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

how to remove the thousand separator using cultureinfo?

$
0
0

I try to remove the thousand separator so I'm experimenting some code, but it throws and exception. I tried with Convert.ToDouble, Convert.ToDecimal etc.

it says:

Convert.ToDouble("1.234,45") threw and exception of 'System.FormatException'

The conversion is thrown from line : Convert.ToDouble()

The argument n2 uses the culturinfo, but I also tried "0.00" both throws the same exception

The whole idea is : how to remove the thousand separator, my input is always in this format: 1.234,54 (comma as decimal and dot as thousand separator)... I like to use it in Textbox GotFocus Event.. so the format should be shown like 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.aspxCultureInfo ci = CultureInfo.GetCultureInfo("NL-be");NumberFormatInfo nfi = (NumberFormatInfo)ci.NumberFormat.Clone();//Now force thousand separator to be empty stringnfi.NumberGroupSeparator = "";//Format decimal number to 2 decimal placesstring decimalFormatted = Convert.ToDouble("1.234,45").ToString("0.00", nfi);string decimalFormatted = Convert.ToDouble("1.234,45").ToString("n2", nfi);

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images