Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force .NET to write native persian numerics instead of US format

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 ?

like image 332
Mohsen Sarkar Avatar asked Oct 21 '22 17:10

Mohsen Sarkar


1 Answers

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']));
like image 154
Alexei Levenkov Avatar answered Oct 27 '22 09:10

Alexei Levenkov