NumberConverter is a simple interface for converting numbers from their numeric representations into their written, lingual representations. Other, probably better solutions already exist (see below), and this was created only as a coding exercise.
$converter = new DrrckNlsn\NumberConverter\EnglishNumberConverter();
echo $converter->convert(1234567);
Output:
one million two hundred thirty four thousand five hundred sixty seven
Currently, there is only an EnglishNumberConverter
implementation, but the
project was created with other languages in mind.
This package comes with a simple CLI binary for demonstrating the
EnglishNumberConverter
class, located at bin/convertNumber
.
The recommended way to install NumberConverter is via Composer:
composer require drrcknlsn/number-converter
After installing the dependency, you will need to require Composer's autoloader:
require 'vendor/autoload.php';
The intl
extension provides the NumberFormatter
class, which can be used to accomplish the same goal, using NumberFormatter::SPELLOUT
.