Skip to content
Devix Open Source
Laravel package v1.0.0 MIT Stable

Laravel Number Words

Numbers and money in words for Laravel — the grammar ICU gets wrong.

composer require devix-labs/laravel-number-words
PHP Laravel
Laravel Number Words

Live demo coming soon

PHP's only real option is ICU, which writes خمسة مائة for five hundred, gets the gender of eleven wrong, has no Arabic ordinals, and answers in English when asked for Urdu. This package spells numbers, money and cheque lines in English, Arabic and Urdu with the agreement each language needs — Blade directives, a facade, and macros beside Laravel's own Number helper. 796 shared vectors keep it identical to the JavaScript package.

What you get

What ICU gets wrong

Number::spell() writes خمسة مائة, mistakes the gender of eleven, has no Arabic ordinals, and returns English for Urdu. All four are correct here.

Blade directives

@words, @money and @cheque — the three things an invoice template needs, following your app's locale unless told otherwise.

Any currency, any language

AED in English, PKR in Urdu, INR in Arabic, with thirteen built in and Currencies::register() for the rest.

Count your own nouns

Give NounForms the four Arabic forms once and every number agrees, from فاتورتان to ألفا فاتورة.

Identical to the browser

796 shared vectors assert the PHP output matches the JavaScript package, so a server-rendered invoice matches the live one.

Laravel Number Words — overview

Why it exists

PHP's only real option is ICU, through Number::spell(). On a current ICU it writes خمسة مائة for five hundred, gets the gender of eleven wrong, has no Arabic ordinals at all, and silently answers in English when asked for Urdu. For an invoice or a cheque, that is not usable.

What it does differently

  • Arabic that agrees. Polarity, duals, the tamyīz, the construct state, both spellings of a hundred.
  • Urdu that exists. All ninety-nine irregular numerals, lakh and crore.
  • Currency and language are independent. AED in English, PKR in Urdu, INR in Arabic.
  • The cheque line, with "only" in the right language.
  • Identical to the browser. 796 shared vectors against the JavaScript package.

Not in 1.0

Invoice and cheque PDF templates (that is the Pro edition's shape), and languages beyond these three — though registerLanguage() takes yours.

How it compares

Questions

Isn't this solved already?

For spelling a number in JavaScript, largely yes — n2words is good and we say so in the teardown. This package exists for three things still missing everywhere: spelling any currency in any language (a Dubai invoice in English, priced in dirhams, which n2words and to-words both refuse), the cheque line with “only” in the right language, and counting your own nouns in Arabic. In PHP nothing usable exists at all.

What is wrong with Arabic in other libraries?

Usually the agreement. Three takes the opposite gender of what it counts (ثلاثة كتب but ثلاث سيارات), two is a dual (درهمان), eleven to ninety-nine take the accusative (أحد عشر درهمًا), a round hundred takes the genitive singular (مئة درهم), and a dual before its noun loses its nūn (مئتا درهم, never مئتان درهم). PHP's ICU gets several of these wrong and writes خمسة مائة for five hundred.

Can I count something other than money?

Yes, and it is the feature we are proudest of. Give counted() the four Arabic forms of your noun once — فاتورة, فاتورتان, فواتير, فاتورةً — and every number agrees, including ألفا فاتورة for two thousand.

Will the amount survive floating point?

Amounts are split and rounded on the digits, never on a float, and the integer side uses bigint, so values past what a double can hold are exact. Pass a string for money that came from a database.

Which currencies are included?

AED, SAR, QAR, KWD, BHD, JOD, OMR, EGP, PKR, INR, USD, EUR and GBP, each with words in English, Arabic and Urdu. KWD, BHD, JOD and OMR divide into a thousand and keep all three digits. registerCurrency() takes your own.