Skip to content

Hex float "X" format doesn't round-trip in built-in cultures with directional marks in their sign strings #135039

Closed

Description

@pawlos

Description

In .NET 11, double/float/Half formatted with the "X"/"x" format cannot be parsed back with NumberStyles.HexFloat using the same culture when the culture's PositiveSign/NegativeSign is not plain "+"/"-" (for example he-IL, ar-*, fa-IR, ur-PK). The formatter always writes the exponent sign as ASCII +/-, but the parser only accepts the culture's PositiveSign/NegativeSign there.

Reproduction Steps

using System;
using System.Globalization;

foreach (string name in new[] { "en-US", "ar-AE" })
{
    var culture = new CultureInfo(name);
    foreach (double value in new[] { Math.PI, -0.1 })
    {
        string s = value.ToString("X", culture);
        bool ok = double.TryParse(s, NumberStyles.HexFloat, culture, out _);
        Console.WriteLine($"{name}: {s} -> parses back: {ok}");
    }
}

Expected behavior

Both cultures print parses back: True, as CultureInfo.InvariantCulture does.

Actual behavior

en-US: 0X1.921FB54442D18P+1 -> parses back: True
en-US: -0X1.999999999999AP-4 -> parses back: True
ar-AE: 0X1?921FB54442D18P+1 -> parses back: False
ar-AE: ?-0X1?999999999999AP-4 -> parses back: False

double.Parse with ar-AE throws FormatException: The input string '0X1.921FB54442D18P+1' was not in a correct format.

Regression?

No, hex floating-point formatting and parsing are new in .NET 11.

Known Workarounds

Use CultureInfo.InvariantCulture for both formatting and parsing.

Configuration

.NET 11.0.0-rc.1.26425.128, linux-x64

Other information

Activity

  1. dotnet-policy-service commented on Oct 1, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-globalization
    See info in area-owners.md if you want to be subscribed.

  2. dotnet-policy-service commented on Oct 1, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-numerics
    See info in area-owners.md if you want to be subscribed.

  3. self-assigned this
    on Oct 1, 2026
  4. added a commit that references this issue on Oct 6, 2026
    4a6440c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions