- Added Boroda's code for localisation of floats when reading the INI files. I can't really test it so hopefully Boroda can give some feedback on that. You will need to change the commas in the INI files back to decimal places or it will fail. Which probably isn't great either but my plan is to get rid of those files.
no, this workaround must
always correctly read US notation (dot) for decimal point,
no matter if current windows locale is US or Russian/European, and
no matter how floats are written to the file (using US notation or
current windows locale notation). if float are written to file using
current locale, which uses commas instead of dot, then Replace('.', localizedDecimalPoint) method just won't replace anything, and all be working fine anyway.
sometimes the problem is that float.Parse() method
always expects string written using
current locale, that's why a workaround is sometimes needed.
note that .ToString() method uses by default (without additional parameters) current user locale.
new plugin version doesn't fix this issue, because i've given you wrong code example. "localizedDecimalPoint" declaration must be of course "static readonly", not "const". expression evaluation after "localizedDecimalPoint" declaration must be done on user's pc (using user current locale), not at compile time.
here is the correct example for reading floats:
static readonly char localizedDecimalPoint = (0.5).ToString()[1]; //global declaration
...
//code inside some function
string number = "0.22"; //it's just input example
number = number.Replace('.', localizedDecimalPoint);
float fpNumber = float.Parse(number);
...
also, i think it's better to write .ini files
always using US notation (
no matter which is
current user locale). you at the moment don't write anything to .ini files by plugin, but if you will be ever, here is the example to
always write floats using
US notation (
no matter if current locale is US or Russian/European):
static readonly char localizedDecimalPoint = (0.5).ToString()[1]; //global declaration
...
//code inside some function
float fpNumber = 0.22f; //it's just output example
string number = fpNumber.ToString().Replace(localizedDecimalPoint, '.');
...