C# WPF Converting english numbers to arabic numbers

前端 未结 2 1038
清歌不尽
清歌不尽 2021-01-07 00:48

I need to display an english double in arabic numerical characters for an application I am working on.

Here is an example class that holds the double:



        
相关标签:
2条回答
  • 2021-01-07 01:06

    I've found a very quick and easy solution to this. I discovered that the use of arabic characters for numbers was contextual; ie the digit shape depends on the previous text in the same output.

    Example: Entering "1234" as the text in a TextBlock element would simply display this in the english shape. However, if 1234 was preceded with some arabic text (let's say "abcde") such as شلاؤيث1234. In this example, then first four digits would be in the arabic shapes for the characters "1234". (Note: this doesn't seem to work in for this website - displays correctly in the text box however the preview shows english shapes for the numbers)

    See these links for more information:

    http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.digitsubstitution.aspx http://msdn.microsoft.com/en-us/library/system.globalization.digitshapes.aspx

    From looking at the second link, the obvious choice I wanted was NativeNational, however since our CurrentCulture is set automatically by the operating system, the CurrentCulture instance is read only.

    To by pass this, I simply created a new CultureInfo object and changed the DigitSubstitution to DigitShapes.NativeNational:

            CultureInfo ci = CultureInfo.CreateSpecificCulture(Thread.CurrentThread.CurrentCulture.Name);
            ci.NumberFormat.DigitSubstitution = DigitShapes.NativeNational;
            Thread.CurrentThread.CurrentCulture = ci;
    
    0 讨论(0)
  • 2021-01-07 01:18

    This looks like it does what you need:

    http://weblogs.asp.net/abdullaabdelhaq/archive/2009/06/27/displaying-arabic-number.aspx

    0 讨论(0)
提交回复
热议问题