From 1dbf9fe2f77bfa63c3f91d256cdd82998b4b175f Mon Sep 17 00:00:00 2001 From: Edward Powell Date: Wed, 30 Apr 2014 19:26:50 -0400 Subject: [PATCH] [units] Improve output for non-sensible mass units --- units.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/units.py b/units.py index 1be9052ff3..272a1bc87d 100644 --- a/units.py +++ b/units.py @@ -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