I'm developing a website for a German Customer. In Germany, they use comma as decimal separator.
I use a WebMethod to get the values from SQL and then build a JSON object to show the data on the website. Using C# SqlCommand, I got the value from SQL as a string. I want to save this value into a double variable.
This is the code example which shows what I want to do:
NumberFormatInfo nfi = new CultureInfo( "de-DE", false ).NumberFormat;
nfi.NumberDecimalSeparator = ","; // Displays the value with a comma as the separator.
string value ="15.95"; //value from SQL
string valueInString = "";
double valueInDouble = 0;
valueInString = Convert.ToDouble(value.ToString()).ToString( "N", nfi );
valueInDouble = Convert.ToDouble(value.ToString()).ToString( "N", nfi ); //Error
valueInDouble = Convert.ToDouble(valueInString,nfi);
Console.WriteLine( valueInString ); // returns 15,95. But it is a string
Console.WriteLine( valueInDouble ); // returns 15.95. the comma is reverted back to dot
I need to save the data as double. How do I resolve this?