1.00 Is the Ugliest Number

Numbers, like Shakira’s hips, don’t lie. But they can get ugly. I mean, how many minutes is 0.375 hours? 19968489 bytes – what’s that in megabytes? And don’t even get me started on trailing zeros. If your app is going to be used by humans, the output needs context.

Fortunately, you can fix all of that with a single Python import. humanize makes your hideous integers, floats, dates, times, and file sizes pretty and fit for human consumption.

```python # Turn floats into fractions > humanize.fractional(.375*60) ‘22 1/2’

Make sense of file sizes

humanize.naturalsize(19968489) ‘20.0 MB’

Add commas to large numbers and trim trailing zeros

humanize.intcomma(humanize.fractional(1239.0)) ‘1,239’

Report time intervals in plain English

humanize.naturalday(datetime.datetime.now() - datetime.timedelta(days=1.3)) ‘yesterday’ ```

Written by Jason Moiron, humanize works with Python 2.7 & 3.3 and is localized for Russian, French, Korean, and English.

Get humanize Discuss it
2017 Neal Shyam