PHP: How to convert a number into a string? [duplicate]

2

I have an application that generates a PDF receipt. But in the bank the values have to be converted into words

BD | PHP

10 | TEN

15 | QUINZE

7 | SEVEN

Is there a function that returns the string of a number in php?

    
asked by anonymous 07.11.2017 / 14:13

1 answer

4

There is a class NumberFormatter that enables this representation of numbers for text.

$word = new \NumberFormatter('pt-BR', \NumberFormatter::SPELLOUT);
echo $word->format(13);
// treze
  

The second parameter of the class is that it defines the output type of the formatting.

This class depends on the package intl to be used, first check if this package is installed with:

php -m | grep intl

If it is already installed, just use it normally, if it is not installed with:

1. Linux: sudo apt-get install php * (version) * - intl

2. Windows: remove the comment on the line with extension=php_intl.dll in your php.ini and restart the http server you are using

    
07.11.2017 / 14:39