This library is meant for general-purpose number spelling for use in, e.g. legal documents and bills.
Supported languages (ISO 639-1 language codes):
- English ('en')
- Estonian ('et')
- Latvian ('lv')
- Lithuanian ('lt')
- Russian ('ru')
- Spanish ('es')
- Polish ('pl')
Supported currencies (ISO 4217 currency codes):
- British Pounds ('GBP')
- Euro ('EUR')
- Latvian Lats ('LVL')
- Lithuanian Lits ('LTL')
- Russian Roubles ('RUR')
- U.S. Dollars ('USD')
- PLN Zloty ('PLN')
Report issues if you find any!
Installation:
composer require jurchiks/numbers2words
To enable the Twig filter in Symfony 4, add it in config/services.yaml
(or its equivalent):
services:
js\tools\numbers2words\Twig\Spell:
tags: [twig.extension]
Usage:
use js\tools\numbers2words\Speller;
Speller::spellNumber(123, Speller::LANGUAGE_RU);
// output: сто двадцать три
Speller::spellCurrency(123.45, Speller::LANGUAGE_ENGLISH, Speller::CURRENCY_EURO, true, true);
// output: one hundred and twenty three euro and forty five cents
Speller::spellCurrencyShort(123.45, Speller::LANGUAGE_ENGLISH, Speller::CURRENCY_EURO);
// output: one hundred and twenty three EUR 45/100
In Twig:
{{ 123.45 | spellCurrencyShort('en', 'EUR') }}
// output: one hundred and twenty three EUR 45/100