
What you need to remember about the decimal separator
Everyone who has ever written programs in C # used such a simple function as


In English-speaking countries, a period is used as a separator, and in other countries, mainly a comma. Everything, in principle, is not bad, and the .Net environment, like most modern programs, knows which separator is used by the system. But a program like Meta Trader was written by Russian programmers who just didn’t know about the separator, and the program alwaysuses a comma by default. It was necessary to implement the transfer from MT4 to the data application and back through sockets. During testing on my computer, strange behavior was not noticed, because I have the default "," in my system. But the program was written for a foreign customer, in theory everything should work just the same. It is not clear for what reason, the data accepted by my program, when translating from a string to Double, was not processed correctly and without any exceptions. For example, the conversion from the string “1.4174” to a number on my computer gave the same result, while the customer’s “1.4174” gave the result 14174, that is, a five-digit number without any delimiters, which was not immediately noticed.
The solution, unlike the error itself, was found instantly - replace the comma with the character used by the system.
Rows:
raise a FormatException if the period is a delimiter in the system.
Replace them with
and the problem is resolved, regardless of what character is used by the system, replacing the comma in the string with this character - we get the appropriate format for conversion.
To change the separator in the system, go here:



I hope you will never forget about this nuance, if you work for a foreign customer. And it will help save some time.
Convert.ToDouble(string value);
I, like the rest, had no problems with it until a certain point. This function has such a feature that is not known to everyone - that the default separator is the one that is on the system. 

In English-speaking countries, a period is used as a separator, and in other countries, mainly a comma. Everything, in principle, is not bad, and the .Net environment, like most modern programs, knows which separator is used by the system. But a program like Meta Trader was written by Russian programmers who just didn’t know about the separator, and the program alwaysuses a comma by default. It was necessary to implement the transfer from MT4 to the data application and back through sockets. During testing on my computer, strange behavior was not noticed, because I have the default "," in my system. But the program was written for a foreign customer, in theory everything should work just the same. It is not clear for what reason, the data accepted by my program, when translating from a string to Double, was not processed correctly and without any exceptions. For example, the conversion from the string “1.4174” to a number on my computer gave the same result, while the customer’s “1.4174” gave the result 14174, that is, a five-digit number without any delimiters, which was not immediately noticed.
The solution, unlike the error itself, was found instantly - replace the comma with the character used by the system.
Rows:
String Source = "0,05";
Double number = Convert.ToDouble(Source);
raise a FormatException if the period is a delimiter in the system.
Replace them with
Char separator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator[0];
String Source = "0,05".Replace( ',' , separator);
Double number = Convert.ToDouble(Source);
and the problem is resolved, regardless of what character is used by the system, replacing the comma in the string with this character - we get the appropriate format for conversion.
To change the separator in the system, go here:



I hope you will never forget about this nuance, if you work for a foreign customer. And it will help save some time.