Lingua::EN::Numbers::Ordinate -- go from cardinal number (3) to ordinal ("3rd")
use Lingua::EN::Numbers::Ordinate; print ordinate(4), "\n"; # prints 4th print ordinate(-342), "\n"; # prints -342nd # Example of actual use: ... for(my $i = 0; $i < @records; $i++) { unless(is_valid($record[$i]) { warn "The ", ordinate($i), " record is invalid!\n"; next; } ... }
There are two kinds of numbers in English -- cardinals (1, 2, 3...), and ordinals (1st, 2nd, 3rd...). This library provides functions for giving the ordinal form of a number, given its cardinal value.
Returns a string consisting of that scalar's string form, plus the appropriate ordinal suffix. Example: ordinate(23) returns "23rd".
ordinate(23)
As a special case, ordinate(undef) and ordinate("") return "0th", not "th".
ordinate(undef)
ordinate("")
This function is exported by default.
Merely an alias for ordinate, but not exported by default.
ordinate
Returns just the appropriate ordinal suffix for the given scalar numeric value. This is what ordinate uses to actually do its work. For example, ordsuf(3) is "rd".
ordsuf(3)
Not exported by default.
The above functions are all prototyped to take a scalar value, so ordinate(@stuff) is the same as ordinate(scalar @stuff).
ordinate(@stuff)
ordinate(scalar @stuff)
* Note that this library knows only about numbers, not number-words. ordinate('seven') might just as well be ordinate('superglue') or ordinate("\x1E\x9A") -- you'll get the fallthru case of the input string plus "th".
ordinate('seven')
ordinate('superglue')
ordinate("\x1E\x9A")
* As is unavoidable, ordinate(0256) returns "174th" (because ordinate sees the value 174). Similarly, ordinate(1E12) returns "1000000000000th". Returning "trillionth" would be nice, but that's an awfully atypical case.
ordinate(0256)
ordinate(1E12)
* Note that this library's algorithm (as well as the basic concept and implementation of ordinal numbers) is totally language specific.
To pick a trivial example, consider that in French, 1 ordinates as "1ier", whereas 41 ordinates as "41ieme".
Lingua::EN::Inflect provides an ORD function, which returns the ordinal form of a cardinal number.
ORD
Lingua::EN::Number::IsOrdinal provides an is_ordinal function, which returns true if passed an ordinal number.
is_ordinal
Lingua::EN::Numbers provides function num2en_ordinal() which will take a number and return the ordinal as a word. So 3 will result in "third".
num2en_ordinal()
https://github.com/neilb/Lingua-EN-Numbers-Ordinate
Copyright (c) 2000 Sean M. Burke. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Sean M. Burke sburke@cpan.org
sburke@cpan.org
This has been maintained by Neil Bowers (NEILB) since 2014.
To install Lingua::EN::Numbers::Ordinate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lingua::EN::Numbers::Ordinate
CPAN shell
perl -MCPAN -e shell install Lingua::EN::Numbers::Ordinate
For more information on module installation, please visit the detailed CPAN module installation guide.