BepInExConfigManager icon indicating copy to clipboard operation
BepInExConfigManager copied to clipboard

Always use InvariantCulture when converting from/to floats

Open benediktwerner opened this issue 2 years ago • 0 comments

Fixes #15

I'm actually rather confused why the current code doesn't already work and just allows me to use , everywhere. After looking into it a bit, apparently, during the first call to InteractiveNumber.RefreshUIForValue, CurrentCulture is set to de-DE i.e. German as expected but on later calls to both it and InteractiveNumber.SetValueFromInput, it's unset. CurrentUICulture is always set to German though but it doesn't seem to impact whether a period or comma is used for parsing and printing.

So during the initial refresh, the input is set to 3,5 but then on all further calls it wants 3.5.

Not really sure why this is, I guess apparently the culture is set per thread and maybe the other calls run in another thread where the culture isn't set or is reset for some reason?

I guess if you know why this happens, maybe you can find a better fix. Otherwise, the proposed changes work as expected though I guess it's a bit annoying to have to specify the culture everywhere and I guess is also a bit brittle since it's easy to forget but not sure there's a much better solution.

benediktwerner avatar Nov 12 '22 11:11 benediktwerner