Revision 92ea69bf lib/utils/text.py

b/lib/utils/text.py
486 486
      raise errors.ProgrammerError("Shell argument '%s' contains"
487 487
                                   " invalid characters" % word)
488 488
  return template % args
489

  
490

  
491
def FormatOrdinal(value):
492
  """Formats a number as an ordinal in the English language.
493

  
494
  E.g. the number 1 becomes "1st", 22 becomes "22nd".
495

  
496
  @type value: integer
497
  @param value: Number
498
  @rtype: string
499

  
500
  """
501
  tens = value % 10
502

  
503
  if value > 10 and value < 20:
504
    suffix = "th"
505
  elif tens == 1:
506
    suffix = "st"
507
  elif tens == 2:
508
    suffix = "nd"
509
  elif tens == 3:
510
    suffix = "rd"
511
  else:
512
    suffix = "th"
513

  
514
  return "%s%s" % (value, suffix)

Also available in: Unified diff