This page looks best with JavaScript enabled

How to Convert Digit to Words in Php Laravel Using Php Built in NumberFormatter Class

 ·  ☕ 1 min read  ·  ✍️ shibu

NumberFormatter

We can convert number to string using php built in class NumberFormatter .

1
2
3
4
<?php
$digit = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $digit->format(264);
// output will be "two hundred sixty-four"

Troubleshooting:

You need to enable php_intl extension, when using NumberFormatter class.
You can enable this from php.ini setting file.

In my case, I am using ubuntu server. I required to install php7.3-intl extension using apt

1
sudo apt install php7.3-intl

I am using php7.3 version. Hence, I have installed php7.3-intl.
Let you are using php7.4, in this case your extension will be php7.4-intl

Once you’ve install extension, you need to enable extension from your php.ini setting file

extension=intl

I am using apache server. So my php.ini file location is

1
/etc/php/7.3/apache2/php.ini

Once, you have changed in php.ini file, You need to restart your apache2 server

1
sudo service apache2 restart
Share on

Shibu Deb Polo
WRITTEN BY
shibu
Web Developer