Skip to content

iOS Numeric Format setting not respected #110430

@LiamMorrow

Description

@LiamMorrow

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

Image

Screenshot showing that the keyboard only allows entering decimals with commas

Image

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

  1. Open iOS settings -> General -> Language
  2. Set language to English
  3. Set Number Format to 1.234.234,83 (the one which uses comma as a decimal separator)
  4. In a Maui app type in a numeric editor (notice iOS presents only a comma as the decimal separator)
  5. 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions