Skip to content

Instantly share code, notes, and snippets.

@gjcourt
Created October 11, 2011 21:52
Show Gist options
  • Save gjcourt/1279569 to your computer and use it in GitHub Desktop.
Save gjcourt/1279569 to your computer and use it in GitHub Desktop.
prettify number
def prettify(value):
decimal, integer = math.modf(value)
decimal = '%0.2f' % decimal
decimal = decimal[decimal.index('.'):]
sign = '' if integer >= 0 else '-'
integer = abs(int(integer))
result = (',' if integer > 1000 else '') + str(integer % 1000)
while integer / 1000 > 1:
integer /= 1000
result = (',' if integer > 1000 else '') + str(integer % 1000) + result
return sign + result + (decimal if decimal != '.00' else '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment