martinjoiner/ordinal-number

Converts numbers to a human readable ordinal form eg. 'first', 'second' or even 'Three thousand five hundred sixty first'

v1.0.0 2016-12-19 16:49 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:18:15 UTC


README

A PHP package for converting numbers to a human readable sentence of it's ordinal form eg. 'first', 'second' or even 'Three thousand five hundred and sixty first'

Latest release supports numbers in the range 1 - 9999.

Installation

Recomended installation via Composer:

	composer require martinjoiner/ordinal-number

See library page on Packagist https://packagist.org/packages/martinjoiner/ordinal-number

Usage example

	// Tell our code to use the namespace
	use MartinJoiner\OrdinalNumber\OrdinalNumber;

	// The following line will output 'three hundred seventy eighth'
	print OrdinalNumber::convert( 378 );

	// The following line will output 'three hundred and seventy eighth'
	print OrdinalNumber::convert( 378, true );

	// The following line will output 'Three hundred and seventy eighth' (notice capitalised)
	print OrdinalNumber::convert( 378, true, true );

convert() method parameters

Required parameters

  • num {integer} A number to be converted (in the range of 1 - 9999)

Optional parameters

  • appendAnd {boolean} - Default: false - Places the word 'and' before the final 2 parts if number above 101 or higher (eg. One hundred and first). Added to support both American and European versions of English language.
  • titleCase {boolean} - Default: false - Capitalises the first letter

To see some working examples simply run index.php

Testing

Tests are written in PHPUnit https://phpunit.de/

    phpunit --bootstrap vendor/autoload.php tests/OrdinalNumberTest