-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
When using decimal.Parse
using the default CultureInfo
(or not specifying one), MAUI does not respect the user's decimal separator options in iOS. Instead, it simply uses the language's default. What this means is that when a user is prompted for numerical, decimal input, the iOS keyboard presents them with a comma
separator (as they have configured), but decimal.Parse treats it as a grouping separator.
Note that if the user specifies a LANGUAGE which uses commas as a decimal separator, everything works as expected and decimal parse treats commas as decimal separators.
Code driving the parsing logic
if (decimal.TryParse(e.NewTextValue, out decimal result))
{
resultLabel.Text = $"Parsed value with default culture: {result}";
}
else
{
resultLabel.Text = "Invalid input";
}
#if IOS
var correctedCulture = CultureInfo.CurrentCulture.Clone() as CultureInfo;
correctedCulture.NumberFormat.NumberDecimalSeparator = NSLocale
.CurrentLocale
.DecimalSeparator;
correctedCulture.NumberFormat.NumberGroupSeparator = NSLocale
.CurrentLocale
.GroupingSeparator;
if (decimal.TryParse(e.NewTextValue, correctedCulture, out decimal result2))
{
resultLabel2.Text = $"Parsed value with culture from IOS settings: {result2}";
}
else
{
resultLabel2.Text = "Invalid input";
}
#endif
Video showing off behaviour
Screen.Recording.2024-12-04.at.12.14.58.mov
Steps to Reproduce
- Open iOS settings -> General -> Language
- Set language to English
- Set Number Format to 1.234.234,83 (the one which uses comma as a decimal separator)
- In a Maui app type in a numeric editor (notice iOS presents only a comma as the decimal separator)
- Notice that decimal.Parse treats the comma as a grouping separator
An example repo for parsing can be found here:
https://github.com/LiamMorrow/maui-decimal-repro
Link to public reproduction project repository
https://github.com/LiamMorrow/maui-decimal-repro
Version with bug
9.0.12 SR1.2
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 18
Did you find any workaround?
Cloning the current culture, then using the proper separators in the clone, and setting it as the current culture on app startup does fix this. See this PR for an example.