hellrage/NC-Reactor-Planner

Config editor does not treat "." as a decimal point, causing it to import incorrect values

Closed this issue · 2 comments

While trying to import Enigmatica 2: Expert's config file, I realised the values it pasted were a bit off from the original values because a stable reactor I created in-game had a heating rate of 84000 HU/s in the program all of a sudden.

After testing around for a couple of seconds I realised that the program currently only treats the comma sign "," as a separator for decimal values, but the values imported from the .cfg file are saved using decimal points ".". This leads to conversion errors when using the import feature, as well as just some minor inconvenience for anyone looking to use "." to separate their decimal numbers.

I'd have two suggestions to address this issue. The first one would be to just use decimal points by default since that's how the floating points are usually written in programming languages (and the config file), but maybe, for compatibility's sake, you could also just add a line that auto-converts any commas to decimal points if you think that's needed.

TL;DR - Importing is currently broken because the program reads floating point values like "3.0" as "30".

Edit - Okay, while I have to admit I don't know squat about C#, apparently their own double.Parse(x) only accepts "," by default, which is... uhh to say the least suboptimal, but to solve it you can simply change your double.Parse(x) calls to instead be double.Parse(x, CultureInfo.InvariantCulture) (being mindful to add "using System.Globalization;" as well, of course) and then it'll accept both commas and decimal points.

Seems like @Anoyomouse already fixed this issue in a merged PR, but it wasn't included in the latest commit I cloned?

Anyways, sorry to bother with an already closed issue, it was apparently just not merged correctly in commit b16dc51

I shouldn't be opening GitHub issues before having my... "morning" coffee. He fixed it in his own fork, but hasn't submitted a PR yet.

Just want to chime in to clear things up

By default .NET adheres to your system regional settings, i.e. if your decimal separator character is set to , then douple.Parse will EXPECT a , not a .

Also, it does the whole digit grouping thing, so if you type in 1,000.0 it'll interpret it as a normal: 1000.0 - Hence why i added the validation the way i did where you deselect the box and the value will change, it'll show you the , getting discarded if you typed 1000,0 and got 10000 instead

I'll make sure this is pulled through and merged, sorry about that