Skip to content

Instantly share code, notes, and snippets.

@yeondudad
Last active October 15, 2015 15:44
Show Gist options
  • Save yeondudad/858503621c74c574e113 to your computer and use it in GitHub Desktop.
Save yeondudad/858503621c74c574e113 to your computer and use it in GitHub Desktop.
def StrNumberCommaInsert(s):
if s.replace('.', '').isdigit():
p = 0
if '.' in s:
p = len(s) - (s.index('.') + 1)
try:
n = int(s)
except ValueError:
n = float(s)
return ("{:,.%sf}" % p).format(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment