martysama0134

constInfo.intWithCommas

Apr 17th, 2022 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. # TRADE_GOLD_WITH_THOUSANDS_SEPARATORS BEGIN
  2. def intWithCommas(x, commasign='.'):
  3.     # alternative of
  4.     # return '{0:,}'.format(x).replace(',', commasign)
  5.     if type(x) not in [type(0), type(0L)]:
  6.         raise TypeError("Parameter must be an integer.")
  7.     if x < 0:
  8.         return '-' + intWithCommas(-x, commasign)
  9.     result = ''
  10.     while x >= 1000:
  11.         x, r = divmod(x, 1000)
  12.         result = "%s%03d%s" % (commasign, r, result)
  13.     return "%d%s" % (x, result)
  14. # TRADE_GOLD_WITH_THOUSANDS_SEPARATORS END
  15.  
Add Comment
Please, Sign In to add comment