GnuplotCSharp icon indicating copy to clipboard operation
GnuplotCSharp copied to clipboard

problem with ToString() in russian

Open alexgubanow opened this issue 9 years ago • 5 comments

In the Russian localization of the character ',' is a decimal separator, and when you call ToString.() method, the line turns like "0,01", and is not correct. The solution is simple, add .Replace ( ',', '.').

alexgubanow avatar Nov 15 '16 21:11 alexgubanow

thanks. Someone else had this same issue in a different country. can you give some examples of the usage? are the , characters in the data, or in function parameters or results, or where?

AwokeKnowing avatar Mar 01 '17 20:03 AwokeKnowing

sorry, but i am don't use anymore GNUplot. but i think it was something like that: stream.WriteLine(y[i].ToString()); //source stream.WriteLine(y[i].ToString().Replace ( ',', '.'));//modifed

alexgubanow avatar Mar 01 '17 20:03 alexgubanow

The problem is when you have some decimal numbers like 0.1 the .ToString() will produce different results depending on current culture stream.WriteLine(y[i].ToString()); //"0.1" with dot in en-US stream.WriteLine(y[i].ToString()); //"0,1" with comma in ru-RU

It's better to use CultureInfo.InvariantCulture in thie case, e.g.: stream.WriteLine(y[i].ToString(CultureInfo.InvariantCulture)); // "0.1" with dot in all cultures

ToniaDemchuk avatar Mar 02 '17 09:03 ToniaDemchuk

but what faster, ToString().Replace ( ',', '.') or ToString(CultureInfo.InvariantCulture)

alexgubanow avatar Mar 02 '17 09:03 alexgubanow

ToString() is equivalent to ToString(CultureInfo.CurrentCulture) So using ToString(CultureInfo.InvariantCulture) instead of ToString().Replace ( ',', '.') will be faster and consistent.

ToniaDemchuk avatar Mar 02 '17 09:03 ToniaDemchuk