4

I have tried to set Culture and UICulture of the ASP.NET application with no success. Also tried it in C# Windows Application.

System.Globalization.CultureInfo a = new System.Globalization.CultureInfo("fa-IR");
a.NumberFormat.DigitSubstitution = System.Globalization.DigitShapes.NativeNational;
string Q = string.Format(a, "{0}", 1234567890); // Output 1234567890 instead of ٠١٢٣٤٥٦٧٨٩

Is there any part that I missed in the code ?

Mohsen Sarkar
  • 5,910
  • 7
  • 47
  • 86
  • If you look at the documentation for the [`DigitSubstitution`](http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.digitsubstitution.aspx) property you can see that it is not used (yet): _The DigitSubstitution property is reserved for future use. Currently, it is not used in either parsing or formatting operations for the current NumberFormatInfo object._ – Martin Liversage Feb 12 '13 at 07:47
  • Related: [Can I change English numbers to Arabic/Persian representations when a control is being rendered?](http://stackoverflow.com/questions/10069826/can-i-change-english-numbers-to-arabic-persian-representations-when-a-control-is) and [Change English numbers to Persian and vice versa in MVC (httpmodule)?](http://stackoverflow.com/questions/13709718/change-english-numbers-to-persian-and-vice-versa-in-mvc-httpmodule) – sloth Feb 12 '13 at 08:18

1 Answers1

3

There is no support in C#/ .Net framework to output numbers with digits other than 0-9 (nor parsing support).

You need to output digits yourself. You should be able to format numbers first using built-in code (to get correct grouping/decimal separtor/currency) and than replace 0-9 with national digits using String.Replace or map digits to characters you need and join them with String.Join.

 var converted = String.Join("", 123490.ToString().Select(c => "٠١٢٣٤٥٦٧٨٩"[c-'0']));
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179