Spreadsheet Import/Export: Fix feet and inch formatting

This commit is contained in:
Ryan Schultz
2023-08-28 10:11:24 -05:00
parent f573871493
commit 676b16bc29
@@ -574,9 +574,10 @@ def format_length(
if imperial_unit == "foot": if imperial_unit == "foot":
feet = int(value) feet = int(value)
inches = (value - feet) * 12 inches = (value - feet) * 12
elif imperial_unit == "inch": elif imperial_unit == "inch":
inches = value % 12 inches = value * 12
feet = int(round((value - inches) / 12))
# Round to the nearest 1/N # Round to the nearest 1/N
nearest = round(inches * precision) nearest = round(inches * precision)
@@ -586,14 +587,22 @@ def format_length(
# If fraction is a whole number, format it accordingly # If fraction is a whole number, format it accordingly
if frac.denominator == 1: if frac.denominator == 1:
if suppress_zero_inches and frac.numerator == 0: if imperial_unit == "inch":
return f"{feet}'" return f"{round(inches)}\""
return f"{feet}' - {frac.numerator}\"" if suppress_zero_inches:
if frac.numerator > frac.denominator: 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:
remainder = frac.numerator % frac.denominator remainder = frac.numerator % frac.denominator
whole = int((frac.numerator - remainder) / frac.denominator) whole = int((frac.numerator - remainder) / frac.denominator)
return f"{feet}' - {whole} {remainder}/{frac.denominator}\"" if imperial_unit == "foot":
return f"{feet}' - {frac.numerator}/{frac.denominator}\"" return f"{feet}' - {whole} {remainder}/{frac.denominator}\""
elif imperial_unit == "inch":
return f"{whole} {remainder}/{frac.denominator}\""
elif unit_system == "metric": elif unit_system == "metric":
rounded_val = round(value / precision) * precision rounded_val = round(value / precision) * precision
return f"{rounded_val:.{decimal_places}f}" return f"{rounded_val:.{decimal_places}f}"