Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Number in word in Twig File

Tags:

twig

I want to convert Price:200$ in words like Price:Two Hundred$.

In twig like this {{ price }} but this is show Number.

Can any one know how it is possible show this price in word in Twig ?

like image 820
Kunwar Siddharth Singh Avatar asked Feb 01 '26 05:02

Kunwar Siddharth Singh


1 Answers

The Intl filter provided by the official Twig's extensions repository can spellout numbers:

{{ 19.2|localizednumber('spellout') }}
{# Output: nineteen point two #}

For this filter to work, the PHP intl extension is needed and the twig/extensions package must be installed.

If you use Twig directly, register the extension like this:

$twig->addExtension(new Twig_Extensions_Extension_Intl());

If you use Symfony, register this service:

services:
    Twig_Extensions_Extension_Intl:
        class: Twig_Extensions_Extension_Intl
        private: true
        tags:
            - { name: twig.extension }
like image 172
Kévin Dunglas Avatar answered Feb 04 '26 01:02

Kévin Dunglas