iOS `Numeric Format` setting not respected
@matouskozak is already working on this.
Since Dec 9, 2024.
Assessment
This issue has not been assessed yet.
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.
Screenshot showing how the default culture parses a decimal, and the correct parsing
Screenshot showing that the keyboard only allows entering decimals with commas
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
https://github.com/user-attachments/assets/1b488061-38eb-4e40-9704-ebc8dc06f89a
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.
Relevant log output
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·