Reading time ~1 minute

NumberFormatter

Today we will talk about the NumberFormatter a class that is part of the Intl (Internationalization Functions) since version 5.0 of PHP.

We can use it to format numbers, currencies, and percentages according to location (L10n).

This class also gives us the possibility to convert number to its spoken form.

Sample Output

  • 1 = one
  • 17 = seventeen
  • 1985 = one thousand nine hundred eighty-five

Sample Code

1 <?php
2 	$numberFormatter = new NumberFormatter('en_EN', NumberFormatter::SPELLOUT);
3 	echo $numberFormatter->format(1);
4 	// The output will be: one
5 
6 	$numberFormatter = new NumberFormatter('en_EN', NumberFormatter::SPELLOUT);
7 	echo $numberFormatter->format(12345);
8 	// The output will be: twelve thousand three hundred forty-five
9 ?>