public char comF, comR; // to correct Comma- / point problem comF : wrong seperator // comR : correct separator string wrongDataFormat = "wrong Data Format"; public void ConvertToDouble(string text, ref double nb) { // Secure Conversion independant of Komma- Version of PC // comF contains String with wrong camma, comR contains string with correct comma // if number format is wrong, result is old number // Call : ConvertToDouble(text,ref number); // removes all thousand- Seperators // examples: (if decimal sep =".") // 1000,000,000.23 --> 1000000000.23 // 1000.000.000,23 --> 1000000000.23 // 0.23 --> 0.23 // 0,23 --> 0.23 // 1000,023 --> 1000.023 // 1000.023 --> 1000.023 // examples: (if decimal sep =",") // 1000,000,000.23 --> 1000000000,23 // 1000.000.000,23 --> 1000000000,23 // 0.23 --> 0,23 // 0,23 --> 0,23 // 1000,023 --> 1000,023 // 1000.023 --> 1000,023 string TestText = (0.1).ToString("f1"); if (TestText.Substring(1, 1) == ".") // Check which is the actual Decimal separator { comF = ','; comR = '.'; } else { comF = '.'; comR = ','; } double number = 0; char[] seps = new char[2]; seps[0] = ','; // both possible decimal seperators seps[1] = '.'; // check if Thousand- group sign is available. If more than one sign, all left signs are removed int index = 0, cnt = 0; while (index > -1) // count number of seperators { index = text.IndexOfAny(seps, index); // look for next position of seps if (index > -1) { cnt++; index++; } } string newtext = text; if (cnt > 1) // If more than one sign, all left signs are removed { string leftSign = text.Substring(text.IndexOfAny(seps), 1); // what is the left sign? newtext = text.Replace(leftSign, "");// Remove all left signs } string help = newtext.Replace(comF, comR); // Change into correct decimal sep if (Double.TryParse(help, out number)) nb = number; else MessageBox.Show(wrongDataFormat); }