Skip to content
Easily get the ordinal 'st', 'nd', 'rd' or 'th' of cardinal numbers.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENSE
README.md
ord.js
package.json

README.md

 _______  _______  ______  
(  ___  )(  ____ )(  __  \ 
| (   ) || (    )|| (  \  )
| |   | || (____)|| |   ) |
| |   | ||     __)| |   | |
| |   | || (\ (   | |   ) |
| (___) || ) \ \__| (__/  )
(_______)|/   \__/(______/ 

Gives you the 'st', 'nd', 'rd' or 'th' of a whole number.

Does not give you anything for zero, negative numbers, NaN, Infinity or real numbers (e.g. 3.14).

Does not give you anything for something which isn't a number.

Example

var a = 21;
console.log('Happy ' + a + ord(a));

Will print out 'Happy 21st'.

Author

Written by Andrew Chilton - Blog - Twitter.

License

Copyright 2013 Andrew Chilton. All rights reserved.

(Ends)

Something went wrong with that request. Please try again.