Skip to content

Takes a number in the range 1-9999 and converts it to a human readable sentence of it's ordinal form eg. 3561 becomes 'Three thousand five hundred sixty first'

Notifications You must be signed in to change notification settings

martinjoiner/ordinal-number

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ordinal Number

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

About

Takes a number in the range 1-9999 and converts it to a human readable sentence of it's ordinal form eg. 3561 becomes 'Three thousand five hundred sixty first'

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages