Skip to content

Instantly share code, notes, and snippets.

@nicbet
Created April 30, 2019 13:11
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 nicbet/1557beafdb3e0ee624cbfb76d623d173 to your computer and use it in GitHub Desktop.
Save nicbet/1557beafdb3e0ee624cbfb76d623d173 to your computer and use it in GitHub Desktop.
Prettier formatting of numbers for Tables in Python
def pretty_num(value, t=5):
if(len(repr(value)) > t):
if(value < 1):
return 0
else:
return '%.2e' % value
else:
return "{:,}".format(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment