Skip to content

Instantly share code, notes, and snippets.

@yetti
Forked from jlbruno/ordinal.js
Last active April 27, 2022 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetti/89343727c21f69f3def33bcb3dadcc1e to your computer and use it in GitHub Desktop.
Save yetti/89343727c21f69f3def33bcb3dadcc1e to your computer and use it in GitHub Desktop.
Javascript Ordinal Numbers
// found here http://forums.shopify.com/categories/2/posts/29259
var getOrdinal = function(n) {
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
}
import numbro from 'numbro'
formatOrdinal(number) {
const suffix = ['th', 'st', 'nd', 'rd']
let idx = number % 100
return (
numbro(number).format({ thousandSeparated: true }) +
(suffix[(v - 20) % 10] || suffix[v] || suffix[0])
)
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment