Download the PHP package himelali/in-words without Composer

On this page you can find all versions of the php package himelali/in-words. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package in-words

Latest Version Total Downloads PHP Version License Stars

in-words

Convert numbers to words in 14 languages. Each language uses its own numbering system (lakh / crore, 万 / 亿 ...) or, with one switch, the international one (million / billion / trillion). It can also write numbers with native digits (৫২৭.৫৬, ५२७.५६, ٥٢٧٫٥٦).

Contents

What's new in 2.0.0

Version 2.0.0 has breaking changes, see Upgrading from 1.x.

Features

Installation

Requires PHP 7.0 or newer.

How to use

1. Convert a number

setNumber() stores the number, so you can read it in several ways:

2. Choose a language

Pass the language code to the constructor, or change it later with setLanguage(). Codes are not case sensitive and accept - or _ (en_IN, en-in).

3. Switch to million / billion / trillion

setInternational(true) (or true as the second constructor argument) uses the international system, setInternational(false) goes back to the language's native one:

The switch changes the words of bn, hi, ur and en_IN, which count in lakh and crore natively. The other languages already count in millions, so both settings give the same words.

4. Decimals

The decimal part is read digit by digit. Pass decimals as strings to keep trailing zeros:

Floats are rounded to 15 significant digits, so they read the same on every PHP version and locale.

5. Native digits

getNumber() writes the number with the language's own digits and decimal separator:

Languages that use the digits 0 - 9 return the number unchanged.

6. Accepted input

Input Example Notes
int 215245
float 527.56 Rounded to 15 significant digits
numeric string '527.50', ' 007 ' Spaces are trimmed, leading zeros ignored, trailing zeros kept
stringable object any object with __toString()

Negative numbers, scientific notation ('1e5'), NAN, INF and numbers with more than 15 integer digits are rejected with an exception, see Error handling.

7. Amount in words (invoices, cheques, receipts)

Read the whole amount and the cents separately and add your currency:

Use ucfirst() for a capital first letter: One thousand two hundred fifty.

8. Laravel

The package needs no service provider. Use it anywhere, or let Laravel inject it:

Or directly in a Blade view:

To use one configuration everywhere, bind it in AppServiceProvider::register():

Supported languages

Code Language Native name Native system Switch changes words Native digits Decimal word
en English English million / billion / trillion no - point
en_IN English (India) English lakh / crore yes - point
zh Chinese (Simplified) 中文 万 / 亿 no - 点
hi Hindi हिन्दी lakh / crore (लाख / करोड़) yes ०-९ दशमलव
es Spanish Español mil millones / billón no - coma
ar Arabic العربية million / milliard (مليون / مليار) no ٠-٩ and ٫ فاصلة
fr French Français million / milliard / billion no - virgule
bn Bengali বাংলা lakh / crore (লক্ষ / কোটি) yes ০-৯ দশমিক
pt Portuguese (Brazil) Português milhão / bilhão / trilhão no - vírgula
ru Russian Русский миллион / миллиард / триллион no - запятая
ur Urdu اردو lakh / crore (لاکھ / کروڑ) yes ۰-۹ اعشاریہ
id Indonesian Bahasa Indonesia juta / miliar / triliun no - koma
de German Deutsch Million / Milliarde / Billion no - Komma
ja Japanese 日本語 万 / 億 / 兆 no - 点

Billion and trillion are translated the way each language says them: French and German use the long scale (milliard / Milliarde = 10⁹, billion / Billion = 10¹²) and Spanish says mil millones (10⁹) and billón (10¹²). Chinese and Japanese express millions in their own system (一百万, 百万 = one million).

Click a language to see its features and examples.

English (en) and English (India) (en_IN) - `en` uses million / billion / trillion, `en_IN` uses lakh / crore (and million / billion with the switch) - Hyphenated tens (`forty-five`), no plural "s" on scale words | Number | `en` | `en_IN` | |---|---|---| | 21 | twenty-one | twenty-one | | 101 | one hundred one | one hundred one | | 215,245 | two hundred fifteen thousand two hundred forty-five | two lakh fifteen thousand two hundred forty-five | | 2,500,000 | two million five hundred thousand | twenty-five lakh | | 10,000,000 | ten million | one crore | | 1,000,000,000 | one billion | one hundred crore | | 527.56 | five hundred twenty-seven point five six | five hundred twenty-seven point five six |
Bengali (bn) - Lakh / crore system, all 100 words from 0 to 99 (`পঁয়তাল্লিশ`, `নিরানব্বই`) - Bengali digits with `getNumber()`: `৫২৭.৫৬` - Unicode NFC normalized text, so it matches text from users and databases | Number | Native | International | |---|---|---| | 45 | পঁয়তাল্লিশ | পঁয়তাল্লিশ | | 101 | এক শত এক | এক শত এক | | 215,245 | দুই লক্ষ পনেরো হাজার দুই শত পঁয়তাল্লিশ | দুই শত পনেরো হাজার দুই শত পঁয়তাল্লিশ | | 2,500,000 | পঁচিশ লক্ষ | দুই মিলিয়ন পাঁচ শত হাজার | | 10,000,000 | এক কোটি | দশ মিলিয়ন | | 527.56 | পাঁচ শত সাতাশ দশমিক পাঁচ ছয় | পাঁচ শত সাতাশ দশমিক পাঁচ ছয় |
Hindi (hi) - Lakh / crore system, all 100 words from 0 to 99 (`पैंतालीस`, `निन्यानबे`) - Devanagari digits with `getNumber()`: `५२७.५६` | Number | Native | International | |---|---|---| | 45 | पैंतालीस | पैंतालीस | | 101 | एक सौ एक | एक सौ एक | | 215,245 | दो लाख पंद्रह हज़ार दो सौ पैंतालीस | दो सौ पंद्रह हज़ार दो सौ पैंतालीस | | 2,500,000 | पच्चीस लाख | दो मिलियन पाँच सौ हज़ार | | 10,000,000 | एक करोड़ | दस मिलियन | | 527.56 | पाँच सौ सत्ताईस दशमलव पाँच छह | पाँच सौ सत्ताईस दशमलव पाँच छह |
Urdu (ur) - Lakh / crore system, all 100 words from 0 to 99 - Urdu digits with `getNumber()`: `۵۲۷.۵۶` | Number | Native | International | |---|---|---| | 45 | پینتالیس | پینتالیس | | 101 | ایک سو ایک | ایک سو ایک | | 215,245 | دو لاکھ پندرہ ہزار دو سو پینتالیس | دو سو پندرہ ہزار دو سو پینتالیس | | 2,500,000 | پچیس لاکھ | دو ملین پانچ سو ہزار | | 10,000,000 | ایک کروڑ | دس ملین | | 527.56 | پانچ سو ستائیس اعشاریہ پانچ چھ | پانچ سو ستائیس اعشاریہ پانچ چھ |
Arabic (ar) - Unit before tens joined with `و` (`واحد وعشرون`) - Singular, dual, plural (3 - 10) and accusative (11 - 99) forms of thousand, million, billion and trillion - Construct form `مائتا ألف` (200,000) - Arabic-Indic digits and decimal separator with `getNumber()`: `٥٢٧٫٥٦` | Number | Words | |---|---| | 21 | واحد وعشرون | | 245 | مائتان وخمسة وأربعون | | 2,000 | ألفان | | 3,000 | ثلاثة آلاف | | 11,000 | أحد عشر ألفاً | | 200,000 | مائتا ألف | | 215,245 | مائتان وخمسة عشر ألفاً ومائتان وخمسة وأربعون | | 527.56 | خمسمائة وسبعة وعشرون فاصلة خمسة ستة |
Chinese (zh) - Myriad system: 万 (10⁴) and 亿 (10⁸) - `零` for skipped places, read once (`一千零一十`, `一亿零一万`) - Leading `一十` read as `十` (`十五`, `十五亿`) | Number | Words | |---|---| | 15 | 十五 | | 101 | 一百零一 | | 1,010 | 一千零一十 | | 215,245 | 二十一万五千二百四十五 | | 100,010,000 | 一亿零一万 | | 1,500,000,000 | 十五亿 | | 527.56 | 五百二十七点五六 |
Japanese (ja) - Myriad system: 万 (10⁴), 億 (10⁸) and 兆 (10¹²) - No `一` before 十, 百 and 千 (`十`, `百一`, `千`), but `一千` inside larger numbers (`二万一千`, `一千万`) | Number | Words | |---|---| | 10 | 十 | | 101 | 百一 | | 1,000 | 千 | | 21,000 | 二万一千 | | 10,000,000 | 一千万 | | 100,000,000 | 一億 | | 1,000,000,000,000 | 一兆 |
Spanish (es) - `cien` / `ciento`, irregular `veintiuno` ... `veintinueve` - Shortened forms before nouns: `veintiún mil`, `un millón`, `veintiún millones` - Long scale: `mil millones` (10⁹) and `billón` (10¹²) | Number | Words | |---|---| | 21 | veintiuno | | 100 | cien | | 101 | ciento uno | | 21,000 | veintiún mil | | 1,000,000 | un millón | | 21,000,000 | veintiún millones | | 2,500,000,000 | dos mil quinientos millones | | 1,000,000,000,000 | un billón |
French (fr) - `vingt et un`, `soixante et onze`, `soixante-dix`, `quatre-vingts`, `quatre-vingt-dix` - Plural `cents` / `vingts` only at the end or before million (`deux cents`, `deux cent un`, `quatre-vingt mille`) - Invariable `mille`, plural `millions` / `milliards` | Number | Words | |---|---| | 21 | vingt et un | | 71 | soixante et onze | | 80 | quatre-vingts | | 81 | quatre-vingt-un | | 99 | quatre-vingt-dix-neuf | | 200 | deux cents | | 201 | deux cent un | | 80,000 | quatre-vingt mille | | 200,000,000 | deux cents millions | | 1,000,000,000 | un milliard |
German (de) - Numbers below a million are one word (`zweihundertfünfzehntausendzweihundertfünfundvierzig`) - Unit before tens (`einundzwanzig`), `eins` / `ein` / `eine` forms - `eine Million`, `zwei Millionen`, `Milliarde` (10⁹), `Billion` (10¹²) | Number | Words | |---|---| | 21 | einundzwanzig | | 101 | einhunderteins | | 1,001 | eintausendeins | | 215,245 | zweihundertfünfzehntausendzweihundertfünfundvierzig | | 1,000,000 | eine Million | | 2,500,000 | zwei Millionen fünfhunderttausend | | 1,000,000,000 | eine Milliarde |
Portuguese (pt, Brazil) - `cem` / `cento`, `e` between hundreds, tens and units (`duzentos e quarenta e cinco`) - `e` before the last group when it is below 100 or a round hundred (`mil e cem`, `um milhão e duzentos mil`) - Short scale: `bilhão` (10⁹), `trilhão` (10¹²) | Number | Words | |---|---| | 21 | vinte e um | | 100 | cem | | 101 | cento e um | | 1,100 | mil e cem | | 1,250 | mil duzentos e cinquenta | | 1,200,000 | um milhão e duzentos mil | | 1,000,000,000 | um bilhão |
Russian (ru) - Feminine thousand: `одна тысяча`, `две тысячи` - Three plural forms: `тысяча` / `тысячи` / `тысяч`, `миллион` / `миллиона` / `миллионов` | Number | Words | |---|---| | 21 | двадцать один | | 1,000 | одна тысяча | | 2,000 | две тысячи | | 5,000 | пять тысяч | | 21,000 | двадцать одна тысяча | | 2,000,000 | два миллиона | | 5,000,000 | пять миллионов |
Indonesian (id) - `se-` for one ten, hundred and thousand (`sepuluh`, `seratus`, `seribu`) - `belas` for 11 - 19, `puluh` for tens | Number | Words | |---|---| | 11 | sebelas | | 12 | dua belas | | 21 | dua puluh satu | | 100 | seratus | | 1,000 | seribu | | 2,000 | dua ribu | | 1,000,000 | satu juta |

API reference

Method Returns Description
new InWord($language = 'en', $international = false) Language code or LanguageInterface instance
setLanguage($language) InWord Change the language (setConfig() is a 1.x compatible alias)
getLanguage() LanguageInterface The active language
getSupportedLanguages() array code => name of all languages
setInternational($enabled = true) InWord true: million / billion / trillion, false: native system
isInternational() bool Current setting
setNumber($number) InWord int, float, numeric string or stringable object
getWord() string The number in words
getNumber() string The number with native digits
toWords($number) string Shortcut for setNumber($number)->getWord()
getVersion() string Package version

All setters return the same instance, so calls can be chained.

Error handling

Every exception extends Himelali\Exception, so one catch handles them all, or catch a specific one:

Exception (Himelali\Exceptions\) Thrown when
InvalidNumberException The value is not a number: wrong type, 'abc', '1e5', NAN, INF
NumberOutOfRangeException Negative, or more than 15 integer digits (extends InvalidNumberException)
UnsupportedLanguageException The language code is not registered
InvalidOptionException setInternational() gets a non-boolean, or an invalid dependency is passed to the constructor
InvalidLanguageException A custom language or its numbering system is invalid
NumberNotSetException getWord() / getNumber() is called before setNumber()
ConversionException A language fails while converting (e.g. a custom language missing a word). PHP warnings and errors are converted too, and the original is available via getPrevious()

Adding a language

Extend Himelali\Languages\Language and define the words. Override a method only where the grammar differs. Keep the parameters untyped like the parent methods (adding a parameter type to an override is a fatal error):

Use it directly, or register a code for it:

Useful properties: $words (0 - n), $tens, $hundred, $scales (a word or [singular, plural]), $point, $digits (native digits), $separator. Useful methods to override: belowHundred(), hundreds(), scale(), pluralForm(), nativeSystem() (e.g. ScaleSystem::indian() for lakh / crore).

Upgrading from 1.x

Package structure

Namespaces map to directories with PSR-4: Himelali\ => src/, Himelali\Tests\ => tests/.

Testing and coding standard

The test suite has no dependencies and runs on every supported PHP version (php tests/run.php). It is verified on PHP 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 and 8.5 (64-bit) and on 32-bit builds.

The code follows PSR-1, PSR-4 and PSR-12. Class constants are declared without a visibility keyword: PSR-12 requires public const only when the minimum PHP version is 7.1 or later, and it is a syntax error on PHP 7.0.

License

The MIT License (MIT). See LICENSE.


All versions of in-words with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package himelali/in-words contains the following files

Loading the files please wait ...