# Ordinal numeral eval script

I made a quick script that allows you to get the ordinal numeral for a given number. If you guys want to use it, feel free.

What I mean by “ordinal number” is that things like \$(count) and such are given as cardinal numbers (1, 2, 3, 4, etc). This script will convert cardinal numbers to ordinal numbers (ie 1st, 2nd, 3rd, etc).

``````\$(eval function o(y) {y=Number(y);if (y!=y) {return "not a number"};let h=y%100,l=y%10,e="th";if(h>10&&h<20){}else if(l==1){e="st"}else if(l==2){e="nd"}else if(l==3){e="rd"}return `\${y}\${e}`}o("\$(count)"))
``````

To change it from using \$(count), change the variable at the end of the eval. Be sure to keep the quotes!

For anyone who is curious, here is a slightly more human readable version.

``````function o(y) {
y = Number(y);
if (y!=y) {
return "not a number"
}
// h is hundreds, l is the last digit (aka "ones"), e is the final ending
let h=y%100,l=y%10,e="th";
if(h>10&&h<20){
// do nothing
}else if(l==1){
e="st"
}else if(l==2){
e="nd"
}else if(l==3){
e="rd"
}
return `\${y}\${e}`
}
o("\$(count)")``````

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.