From e06acab39be2cd5e2615faa5330eaf2224492827 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 7 Sep 2023 10:13:00 +1000 Subject: [PATCH] Revert "Spreadsheet Import/Export: Fix feet and inch formatting" This reverts commit 921d412fc73268ef0c4d6c8a42620afe5e1d761b. --- .../ifcopenshell/util/unit.py | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index e3dc8aa6d0..d9c3c4259b 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -574,10 +574,9 @@ def format_length( if imperial_unit == "foot": feet = int(value) inches = (value - feet) * 12 - elif imperial_unit == "inch": - inches = value * 12 - + inches = value % 12 + feet = int(round((value - inches) / 12)) # Round to the nearest 1/N nearest = round(inches * precision) @@ -587,22 +586,14 @@ def format_length( # If fraction is a whole number, format it accordingly if frac.denominator == 1: - if imperial_unit == "inch": - return f"{round(inches)}\"" - if suppress_zero_inches: - if imperial_unit == "foot": - return f"{round(value)}'" - elif not suppress_zero_inches: - if imperial_unit == "foot": - return f"{round(value)}' - 0\"" - if frac.numerator > frac.denominator and not frac.denominator == 0: + if suppress_zero_inches and frac.numerator == 0: + return f"{feet}'" + return f"{feet}' - {frac.numerator}\"" + if frac.numerator > frac.denominator: remainder = frac.numerator % frac.denominator whole = int((frac.numerator - remainder) / frac.denominator) - if imperial_unit == "foot": - return f"{feet}' - {whole} {remainder}/{frac.denominator}\"" - elif imperial_unit == "inch": - return f"{whole} {remainder}/{frac.denominator}\"" - + return f"{feet}' - {whole} {remainder}/{frac.denominator}\"" + return f"{feet}' - {frac.numerator}/{frac.denominator}\"" elif unit_system == "metric": rounded_val = round(value / precision) * precision return f"{rounded_val:.{decimal_places}f}"