Skip to content

Commit

Permalink
[units] Improve output for non-sensible mass units
Browse files Browse the repository at this point in the history
  • Loading branch information
embolalia committed Apr 30, 2014
1 parent a941d72 commit 1dbf9fe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions units.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,21 @@ def mass(bot, trigger):
elif unit in ("oz", "ounce"):
metric = numeric * 28.35

pound = metric / 453.6
# TODO: Someone who uses and understands Imperial units should "fix" this
# to not display them as decimal points, but rather as weird Imperial
# 1 pound, 2 ounces or whatnot

if metric >= 1000:
metric_part = '{:.2f}kg'.format(metric / 1000)
else:
metric_part = '{:.2f}g'.format(metric)

bot.reply('{} = {}lb'.format(metric_part, pound))
ounce = metric * .03527
pound = int(ounce) // 16
ounce = ounce - (pound * 16)

if pound > 1:
stupid_part = '{} pounds {:.2f} ounces'.format(pound, ounce)
else:
stupid_part = '{:.2f} oz'.format(ounce)

bot.reply('{} = {}'.format(metric_part, stupid_part))

if __name__ == "__main__":
from willie.test_tools import run_example_tests
Expand Down

0 comments on commit 1dbf9fe

Please sign in to comment.