Skip to content

Instantly share code, notes, and snippets.

View samryl's full-sized avatar

Samryl samryl

  • Phoenix, Arizona
  • 04:47 (UTC -06:00)
View GitHub Profile
@samryl
samryl / addcommas.py
Last active July 8, 2018 22:28
Add Commas to Number (Python)
def add_commas(number):
"""Add commas to a number every 3 places and return the result as a string.
Handles positives/negatives, cases where 0 < abs(x) < 1, and numbers
passed as a string."""
# Ensure that the argument is a string
number = str(number)
isnegative = number[0] == "-"