The rules are as follows:
1. st is used with numbers ending in 1 (e.g. 1st, pronounced first)
2. nd is used with numbers ending in 2 (e.g. 92nd, pronounced ninety-second)
3. rd is used with numbers ending in 3 (e.g. 33rd, pronounced thirty-third)
Note* : As an exception to the above rules, all the "teen" numbers ending with 11, 12or13 use -th (e.g. 11th, pronounced eleventh, 112th, pronounced one hundred
[and] twelfth)
th is used for all other numbers (e.g. 9th, pronounced ninth).
The following JavaScript code (rewritten in Jun '14) accomplishes this:
functionordinal_suffix_of(i) {
var j = i % 10,
k = i % 100;
if (j ==1&& k !=11) {
return i +"st";
}
if (j ==2&& k !=12) {
return i +"nd";
}
if (j ==3&& k !=13) {
return i +"rd";
}
return i +"th";
}
Posted by: Guest
on August-12-2020
Code answers related to "javascript convert number to ordinal"
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email