Urgent.News

What's breaking now, across thousands of outlets.

Tech

Spelling numbers in Arabic is harder than it looks: the four rules behind tafqeet

Most "number to words" libraries translate digits one at a time. That works in English and fails in Arabic on the very first cheque. I maintain an Arabic number-to-words converter (تفقيط) used for invoices and cheques, and these are the rules that broke every naive version I wrote. 1. Units come before tens English says twenty-five . Arabic says five and twenty : خمسة وعشرون . Any loop that walks…

The task of spelling numbers in Arabic is more complex than it appears, requiring adherence to four specific rules. The first rule states that the units come before the tens in Arabic. While English expresses twenty-five as twenty-five, Arabic instead says five and twenty, or خمسة وعشرون. Any algorithm that processes digits from left to right and concatenates the words will produce "عشرون وخمسة," which a bank clerk would immediately identify as incorrect.

The second rule of number spelling in Arabic is that the numbers three to ten take on the opposite gender of the counted noun. This rule is often overlooked. For example, when counting a masculine noun like جنيه (dinar), one and two agree with the noun, but three to ten adopt the opposite gender. Therefore, you would say 1 جنيه واحد ليرة and 3 ثلاثة جنيهات or 3 ليرات if referring to the feminine noun ليرة (lira).

The words from 3 to 10 depend on the currency used, not just the number itself. Consequently, a converter that permanently hard-codes "ثلاثة" is accurate for pounds but incorrect for lira.

The third rule further complicates the process. The counted noun changes form according to its last two digits. This rule makes the use of a lookup table impractical, as the form of the noun depends on the last two digits of the amount. For instance, the numeral for 300 would be "ثلاثة آلاف" (three thousand), while 1100 would be "أحد عشر ألفاً" (eleven hundred) and 100000 would be "مائة ألف" (one hundred thousand).

This rule also applies to scale words, explaining why 3000 is "ثلاثة آلاف" but 11000 is "أحد عشر ألفاً" and 100000 is "مائة ألف."

Lastly, the fourth rule involves the special case of two hundred. On its own, "مائتان" is used, but when followed by a noun, it becomes مائتا ألف or مائتا جنيه. The dual form in a construct loses its final ن, which means a converter that generates "مائتان ألف" would be off by a single character. This character is what a proofreader meticulously checks for. A converter that correctly handles these rules would emit "مائتان ألف" when appropriate, ensuring the number is spelled accurately.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Tuesday 22 September →