From 6616111fbfd84739e426f51f627093a1dfb15780 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 8 Sep 2026 10:18:53 +0200 Subject: [PATCH] Fix Architectural and Engineering inch unit formatting Suppress leading 0 feet notation when feet = 0 in architectural (LUNITS 4) and engineering (LUNITS 3) formats. Values less than one foot should display as inches only (e.g. 9 1/4 inches instead of 0 feet 9 1/4 inches). - For Architectural: 9.25 inches now displays as 9 1/4 inch mark instead of 0 feet 9 1/4 inch mark - For Engineering: 11.94 now displays as 11.9 inch mark instead of 0 feet 11.9 inch mark - Proper feet notation is preserved for values >= 1 foot - Updated tests to reflect correct expected values Fixes issue 1066 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/entities/common.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/entities/common.rs b/src/entities/common.rs index 1f837daca..cc3ed1cc5 100644 --- a/src/entities/common.rs +++ b/src/entities/common.rs @@ -142,7 +142,13 @@ pub fn format_length(value: f64) -> String { }; let unit_suffix = if ctx.lunits == 4 { "\"" } else { "" }; match feet { - Some(f) => format!("{}{:.0}'-{:.0}{}{}", sign, f, whole, frac_str, unit_suffix), + Some(f) => { + if f == 0.0 && whole > 0.0 { + format!("{}{:.0}{}{}", sign, whole, frac_str, unit_suffix) + } else { + format!("{}{:.0}'-{:.0}{}{}", sign, f, whole, frac_str, unit_suffix) + } + } None => format!("{}{:.0}{}", sign, whole, frac_str), } } @@ -1102,7 +1108,7 @@ mod length_format_tests { #[test] fn architectural_carries_into_feet() { - assert_eq!(with_units(4, 4, 11.99), "0'-11 63/64\""); + assert_eq!(with_units(4, 4, 11.99), "11 63/64\""); assert_eq!(with_units(4, 4, 11.999), "1'-0\""); assert_eq!(with_units(4, 4, 23.999), "2'-0\""); assert_eq!(with_units(4, 4, 66.5), "5'-6 1/2\""); @@ -1111,7 +1117,7 @@ mod length_format_tests { #[test] fn engineering_carries_into_feet() { - assert_eq!(with_units(3, 1, 11.94), "0'-11.9\""); + assert_eq!(with_units(3, 1, 11.94), "11.9\""); assert_eq!(with_units(3, 1, 11.99), "1'-0.0\""); assert_eq!(with_units(3, 1, 23.99), "2'-0.0\""); assert_eq!(with_units(3, 2, 11.999), "1'-0.00\"");