Skip to content

Instantly share code, notes, and snippets.

@gabrielpjordao
Last active December 17, 2015 10:28
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 gabrielpjordao/5594842 to your computer and use it in GitHub Desktop.
Save gabrielpjordao/5594842 to your computer and use it in GitHub Desktop.
def do_humanize_int(value, ignore_decimals=True):
if not value:
return value
number = float(value)
scales = [
(u'trilhão',u'trilhões'),
(u'bilhão', u'bilhões'),
(u'milhão', u'milhões'),
('mil', 'mil')
]
while number > 1000:
number = round(number / 1000, 1)
units = scales.pop()
single, plural = 0, 1
category = single
if number >= 2:
category = plural
if ignore_decimals:
number = int(number)
humanized_int = '%s %s' % (number, units[category])
return humanized_int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment