Skip to content

Conversation

@zzzbatmand
Copy link
Contributor

Scandinavian and some other regions use Comma (,) instead of Period (.) for decimal places.
This causes some issues when entering float values, by the values going haywire and jumping all over the place.
image
This simple fix just replaces the comma with a period and seems to fix the issue.

NOTE: I have only tried this with Danish Culture, so there might be some issue with other cultures I haven't happened upon.

Scandinavian and some other regions use Comma (,) instead of Period (.) for decimal places. This causes some issues when entering float values, so this fixes it by just replacing the comma.
@zzzbatmand zzzbatmand changed the title Fixed decimal for Scandinavia and similar. Fixed decimal for Scandinavia and similar Culture Apr 14, 2025
@zzzbatmand zzzbatmand changed the title Fixed decimal for Scandinavia and similar Culture Fixed decimal for Scandinavian and similar Culture Apr 14, 2025
Copy link
Member

@ManlyMarco ManlyMarco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the comma come from? Rather than replacing it, the better way would be to fix whatever is producing it. I would guess it's some conversion that is missing StringConverter.InvariantCulture in its parameters.

@zzzbatmand
Copy link
Contributor Author

zzzbatmand commented Apr 15, 2025

Where does the comma come from? Rather than replacing it, the better way would be to fix whatever is producing it. I would guess it's some conversion that is missing StringConverter.InvariantCulture in its parameters.

From what I could gather, it's due to the .ToString() when converting from floats/double to string.
It is possible to pass a NumberFormatInfo to the float.ToString(), the issue is that the code also uses object.ToString() and this function doesn't have an overload for NumberFormatInfo.
Alternatively it would be possible to check the type of the object and then cast it to a float/double, but the simple .Replace() seemed like the simplest fix.

I tried adding this check and it has the same result. It's just a lot more code.

// Original code
// var strVal = value.ToString().AppendZeroIfFloat(setting.SettingType);

// My change
var strVal = "";
if (setting.SettingType == typeof(float))
{
    strVal = ((float)value).ToString(nfi);
}
else if (setting.SettingType == typeof(double))
{
    strVal = ((double)value).ToString(nfi);
}
else if (setting.SettingType == typeof(decimal))
{
    strVal = ((decimal)value).ToString(nfi);
}
strVal = strVal.AppendZeroIfFloat(setting.SettingType);

I can update the PR if this solution is more favorable.

@ManlyMarco
Copy link
Member

Just do .ToString(CultureInfo.InvariantCulture).

@zzzbatmand
Copy link
Contributor Author

zzzbatmand commented Apr 15, 2025

Just do .ToString(CultureInfo.InvariantCulture).

object.ToString() does not have any overload functions, meaning the example you are stating, does not exist.
I have found that Convert.ToString(rawValue, CultureInfo.InvariantCulture) does work.

The issue with that is in the function private void DrawUnknownField(SettingEntryBase setting, int rightColumnWidth) at the line var text = setting.ObjToStr(setting.Get()).AppendZeroIfFloat(setting.SettingType); the setting.ObjToStr(setting.Get()) is not possible to make InvariantCulture.
Arguably this shouldn't be an issue, as the function is defined by the creator of the setting, and they should therefore have handled this case.

I have updated the PR, is this an acceptable solution?

Copy link
Member

@ManlyMarco ManlyMarco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

@ManlyMarco ManlyMarco merged commit 1ca4951 into BepInEx:master Apr 16, 2025
starfi5h pushed a commit to starfi5h/BepInEx.ConfigurationManager that referenced this pull request Oct 31, 2025
Scandinavian and some other regions use Comma (,) instead of Period (.) for decimal places. This causes some issues when entering float values.

(cherry picked from commit 1ca4951)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants