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}"