caubert

ordinalSuffix

Feb 17th, 2020
383
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {{ $ordinal := "th" }} {{/* default ordinal value in most cases is set here */}}
  2.  
  3. {{ $n := (parseArgs 1 "" (carg "int" "int") ).Get 0 }}
  4. {{ $x := div (toInt (mod $n 100) ) 10 }}
  5. {{ $y := toInt (mod $n 10) }}
  6.  
  7. {{ if eq $x 1 }} {{/* ordinal remains unchanged so this is "break" */}}
  8. {{ else if eq $y 1 }} {{ $ordinal = "st" }}
  9. {{ else if eq $y 2 }} {{ $ordinal = "nd" }}
  10. {{ else if eq $y 3 }} {{ $ordinal = "rd" }}
  11. {{ end }}
  12.  
  13. {{ joinStr "'" $n $ordinal }}
RAW Paste Data