-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
دعم القروش #6
Comments
Please visit this page: for a work in progress on a new fully featured library. Please see the readme file. |
Thank you! One really long page! how will it be different than the current "Tafqit" code? |
arqamAR is a large code (40k minified) and completely comprehensive as it provides lots of features and options for fraction numbers and for 173 currencies plus abilities to add more currencies and subjects, but 60% of the size are the tables for currencies information and very large numbers handling. With regards to .NET, what is the core programming language you used (I never tried .NET :-)) If you translated it to .NET in that case, I do not recommend that you add that part for "نصب جر", i.e. the option {AG} as this will require additional code once you use fractions or currencies. It is easy to remove it (only 5 lines need modification). It would be good to have a look at your .NET code, I might learn something new. Regards |
I am using C#.NET. I don't think you should find trouble learning it, you already know the programming concepts and there are tons of tutorials out there. Frankly I didn't apply all the options, most of the non-required options in my particular case was set to a default values in the function call as they are sent as parameters. So it is probably uglier that it should be. But it's a good start -thanks to you!- if someone needs to follow your steps on a .NET application :). I also had to handle the piasters/fractions case by splitting the number by the '.' and calling the function twice, then handling the case for fractions when it is a single digit, 0.2 for example, since it will be sent to the function as 2, to multiple by 10 in that case, so it would result in 20 'عشرون قرشا' instead of just '2'. So in brief:
|
Main Tafqit Function...
|
//------------------------------------------------------------------
|
Usage
|
Thanks for the code. I tried to run it here https://dotnetfiddle.net/ but I get errors. Maybe you add some examples to write to the console. |
In your case, because you use Egyptian Pound and Qirsh which are both male units, then almost 40% of the code is not needed which deals with female units 😉 |
You are right, as I said it is not a pretty conversion, I am in a hurry, it should be done properly. But it works for now. Sorry for my poor usage documentation. I have prepared a fiddle here https://dotnetfiddle.net/R7o3bG |
Thanks a lot. Good job. I will study the code and it will be my first exercise in learning C#. |
Can you please direct massage me on twitter at my twitter account: @maalyafei |
In the C# code, I have noticed the following errors in the output: 200 gives "مئتان جنيه". It should be "مئتا جنيه". You missed enabling the "TextToFollow" flag, which is needed always because there is always text after the number. The code breaks if you enter a number from trillion and above as you are using int32 in the manipulation of the numbers. Last, if you give a number like 20.001 it will give "فقط عشرون جنيهاً وصفر لا غير". I think this is because of the way you do the rounding. |
See here a new version in C# I have customized it to specifically deal with only EGP. But can also be used for any Male/Male currency by a few text changes. Male/Male Currency is like Egyptian Pound as it has both Male Major Unit "جنيه" and also Male Minor Unit "قرش". I have simplified lots of the code and used strings for handling the number so that there is no limit on the size of the number. It is my first attempt at C#. Note that I used local functions to simplify the function calls. This needs version 7 or later of C#. I will update and improve it when I learn more of C#. |
Please note that I have updated the C# code and removed the arrays and the code that copies arrays across for better performance. Now it is a shorter code. The female table was needed to handle the Hundreds because the word "مئة" in Arabic is a female word. The new single array now serves the purpose of all cases with a modified triplet conversion code. |
I don't use twitter much, it's unfortunate that GitHub doesn't have messaging! Thank you very much for optimizing the code, I see you got around C# quite fast 👍 .
That part actually is somewhat correct, Egypt uses 2 decimal places for "قروش" anything that comes after that should be "مليم" which is a currency we no longer use really. That's why I round the value to the nearest "قرش". |
Great. I have posted in the same folder a few other currencies. In particular, the Kuwaiti Dinar in which 1 Dinar is 1000 fils. This, as you can see, does not require additional code. The concept I believe is that the function code should not try to attempt to do rounding. Rounding should be done before it is passed to the function. The idea is that the code is a 'translator' of numbers to words and must not attempt to do any math. For example: if you pass the number Egyptian Pound: 3.99999 . It should only pick 3.99 and convert that to text and not change it to 4 pounds because the developer should have passed 3.99 in the first place. Converting currencies to words is easier than doing normal numbers which have fractions because it then becomes complex and people have different tastes of how they want the output to be written; currency output text on the other hand pretty standard. With currencies, there are other considerations (options) you may need to look into: Example: 0.23 could be written (like now) صفر جنيه وثلاثة وعشرون قرشاً Yes C# is interesting and the only thing I don't like about it is that it is a Typed Language, reminds me of VBA. Best regards |
I agree 100%, I used your updated code for C#, did the rounding before and passed it to the function. This makes much more sense indeed, the function should not be doing any math.
I like this one better, short to the point and clear, having "صفر جنيه " before that might be a little disorienting, no one really says that in day to day life. How do we enable this option through the code? Or did you mean this has a different approach?
This is also a great option it helps keep things clear. I am not an experienced C# developer, but I did use VBA back in the days, I think the whole .NET is the same just with different flavors, C#, VB, ASP... Have a nice day, |
btw, The code misses the 2000, I'm getting ألف instead of ألفا or ألفين... I think line 154 should be instead of |
Thanks, absolutely correct. My quick updates and changes missed this one. This is the problem with Arabic. We say "الفا جنيه" "مليونا جنيه" if there is no number with it, but say "ألفان" and "مليونان" if there is a number with it. This is in fact the purpose of calculating the flag 'IsLastEffTriplet' to find out when the triplet we manipulate has no longer any valid triplets on its right hand (i.e. all remaining are 0 triplets on the RH). Thanks again. |
I have now updated and corrected the code.
I have added another test file here: The test file was copied from arqamAR which has a selected set of numbers to test all parts and sections of the code. It is a bit large file. It is good to run it when you change or optimize the code. |
Well done, I wonder if you will support sub currency as well (قروش)
Also would you happen to have a .Net version of this?
The text was updated successfully, but these errors were encountered: