-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force decimal separator in browsers #16236
Comments
I suspect your |
Can you please file a minimum sample or ar least the converter impl? I guess you just need to consume the correct culture. CultureInfo class has some info about current culture btw. |
@stevemonaco @timunie finally got time to check for culture. public class MathConverter : IValueConverter
{
object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value == null)
return value;
if (parameter == null)
return value;
if (value is double v && parameter is string p && targetType.IsAssignableTo(typeof(double)))
{
var args = p.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (args.Length % 2 != 0)
throw new ArgumentException("ConverterParameter should contain '{operation} {value}'");
for (var i = 0; i < args.Length; i += 2)
{
double opv = double.Parse(args[i + 1], CultureInfo.InvariantCulture); // <- Added InvariantCulture here
v = args[i + 0] switch
{
"div" => v / opv,
"mul" => v * opv,
"add" => v + opv,
"sub" => v - opv,
_ => v,
};
}
return v;
}
else
{
return value;
}
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
} So, now it works with all browsers that i've tested previously. |
Culture passed in the converter is a UI culture by default, retried from the .NET BCL. Unless it was redefined in the Binding - which is the way how you can force it. But yes, if you want it to be always invariant in the converter - just use CultureInfo.InvariantCulture |
Is your feature request related to a problem? Please describe.
I had a problem with a custom converter, which takes a double as it's argument. Like '2.3'
Because my system settings uses a dot (.) as a decimal separator, i haven't ever experienced any problems with that
![Screenshot1](https://private-user-images.githubusercontent.com/20259054/345905446-783df53f-5003-484c-9af6-8732a627866b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1Mzc3ODksIm5iZiI6MTcyMDUzNzQ4OSwicGF0aCI6Ii8yMDI1OTA1NC8zNDU5MDU0NDYtNzgzZGY1M2YtNTAwMy00ODRjLTlhZjYtODczMmE2Mjc4NjZiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA5VDE1MDQ0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI0NDU1YzFkZTBjZmU0NjIxNzBiNWM4YTFiZTdiNDY3MTEyMmJkZTFiNmYzYjg2NGYxMWIzOGUwYmFiNjFlMjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.T5gI1tpGF_IWEQGtFg-VKsWdtCIhneDu9-jq--dHnjU)
Until now, for some reason my converter worked in previewer and in desktop builds:
However it didn't work in any of my browsers (Firefox dev 128.0b9; Google Chrome 126.0.6478.127; MS Edge 126.0.2592.87)
![изображение](https://private-user-images.githubusercontent.com/20259054/345906378-3321466b-aa83-4336-a9ed-9f9929b6331c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1Mzc3ODksIm5iZiI6MTcyMDUzNzQ4OSwicGF0aCI6Ii8yMDI1OTA1NC8zNDU5MDYzNzgtMzMyMTQ2NmItYWE4My00MzM2LWE5ZWQtOWY5OTI5YjYzMzFjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA5VDE1MDQ0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVlYjRlYjA0Yzg5NDVmNDBhNWMyMDA0M2NlZmY5NGVhYzQ5M2U1YjkwZGExMWVlZWFiYzI0YTJmZDllYjI5ZDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.vV8-aLTNqJ5ookpgqxfTeM0y96dCobtM6QFQSHFZgnY)
Until i specifically installed in my Firefox browser an en-GB locale as suggested in this ticket on Mozilla support: (https://support.mozilla.org/en-US/questions/1172233)
Describe the solution you'd like
Maybe somehow force these types of settings to match the globalization settings of UI thread?
(I can't confirm if this is a C# side problem or a Browser side problem because debugging isn't working. Maybe i'll try to force globalization settings for UI Thread later)
Or give a warning that this can happen and avoid parsing doubles altogether.
Describe alternatives you've considered
As for now, changing locale of browser to one that uses decimal separator as yours are works as a fix, but it's not consumer friendly...
Additional context
No response
The text was updated successfully, but these errors were encountered: