Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can i Sum in Gujarati numbers in C# Windows application.

Example: ૨૦૦૦ + ૨૦૦૦ = ૪૦૦૦
in gujarati sum.
Posted
Comments
Maciej Los 3-Sep-15 1:45am    
What have you tried? Where are you stuck?
Sergey Alexandrovich Kryukov 3-Sep-15 2:29am    
Good point, but some general directions can already be given. Please see Solution 1.
—SA
Sergey Alexandrovich Kryukov 3-Sep-15 2:15am    
All right, this is quite possible. What have you tried so far?
—SA

1 solution

First of all, Gujarati digits take the range of Unicode code points 0AE6 to 0AEF and have the same order than traditional Westen Arabic digits 0 to 9: http://unicode.org/charts/PDF/U0A80.pdf[^].

Therefore, you can, for example, convert from Arabic to Gujarati and back using a simple shift. To get a code point from .NET char, you can use these functions:
https://msdn.microsoft.com/en-us/library/z2ys180b%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.char.convertfromutf32%28v=vs.110%29.aspx[^].

Now, I advise the following scenario: don't try to do numeric arithmetic on those strings. Instead, develop two methods: parsing a Gujarati number into the numeric type your are interested in (say, int or long) and representing the number as a Gujarati numeral string. In other words, create two "Gujarati versions" of functions analogous to int.Parse (or int.TryParse) and int.ToString. When it's done, you can parse strings to number, do your addition (subtraction, multiplication) in numbers and then represent numbers as strings.

—SA
 
Share this answer
 
Comments
Maciej Los 3-Sep-15 2:34am    
Well, a 5!
I saw very poor "converter", which "translate" each digit. Please see: http://go2ashutosh.blogspot.com/2011/03/class-to-convert-number-to-gujarati.html
Sergey Alexandrovich Kryukov 3-Sep-15 2:38am    
Thank you, Maciej.
I did not evaluate efficiency of this code, as it looks too trashy to examine it. :-)

As far as I understand, the Gujarati notation for numbers (how numeric strings are composed from individual digits) should be the same as in Western Arabic. It would call for a very quick and dirty solution, which nevertheless would show the performance only slightly worse than that of int.Parse and int.ToString: replace all digits to Western Arabic and call Parse, and, at the end, call ToString and replace all digits with Gujarati. Alternatively, these simple algorithm can reproduce that of Parse (TryParse) and ToString, with shifted code points...

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900