Skip to content

Using NativeDigits and DigitSubstitution in formatting numbers #47749

@arfilon

Description

@arfilon

Hello

I am considering emplement NumberFormatInfo.DigitSubstitution property. since the remark section in (https://docs.microsoft.com/en-us/dotnet/api/system.globalization.numberformatinfo.digitsubstitution?view=net-5.0)
says
The DigitSubstitution property is reserved for future use. Currently, it is not used in either parsing or formatting operations for the current NumberFormatInfo object.

I found that limitation during my work on formating some dates to Arabic, I found that the Arabic Numbers Already exist in the dot net.

          decimal value = -123456.789M;

           var defaultResult = value.ToString();
           var info =new System.Globalization.CultureInfo("ar-JO");
           var format = info.NumberFormat;
           format.DigitSubstitution = System.Globalization.DigitShapes.NativeNational;
           format.NegativeSign = "x";
           var expectedResult = 
               format.NegativeSign 
               + string.Concat(format.NativeDigits[1..7]) 
               + format.NumberDecimalSeparator 
               + string.Concat(format.NativeDigits[7..10]);



           System.Threading.Thread.CurrentThread.CurrentCulture = info;
           var actualResult = value.ToString();
       

image

as you can see the actualResult contains the correct NegativeSign Property and NumberDecimalSeparator Property, but not NativeDigits.

I believe many changes have to be done on Number.Formatting.cs ( https://github.com/dotnet/runtime/blob/69f260eff523bc16c8a95c232e4816b3a1764e88/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs )

and maybe some change needed in other places.
System.Globalization.DigitShapes have 3 items
NativeNational, None and Context, the first one need some work, but the last one may be challenging.

this issue to discuss this change, and figuring out what I do not know about this. before I get started.

thanks for the Input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.GlobalizationquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions