drrcknlsn/number-converter

A tool to convert numbers to their written lingual form.

dev-master 2014-12-03 05:31 UTC

This package is not auto-updated.

Last update: 2024-06-04 00:22:41 UTC


README

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.

Example

$converter = new DrrckNlsn\NumberConverter\EnglishNumberConverter();
echo $converter->convert(1234567);

Output:

one million two hundred thirty four thousand five hundred sixty seven

Internationalization

Currently, there is only an EnglishNumberConverter implementation, but the project was created with other languages in mind.

Demo

This package comes with a simple CLI binary for demonstrating the EnglishNumberConverter class, located at bin/convertNumber.

Installing via Composer

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';

Existing Solutions

The intl extension provides the NumberFormatter class, which can be used to accomplish the same goal, using NumberFormatter::SPELLOUT.