From b709439b65a074b2d5b025e45ad42bf3a44537ff Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 24 Aug 2025 14:23:33 -0700 Subject: [PATCH] Avoid showing 0.0 if there are non-zeros If the value we want to show is in nm but we are representing it as mm, don't show 0.00 unless it is actually 0. otherwise, convert to scientific notation to represent the value in nm. --- common/eda_units.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/common/eda_units.cpp b/common/eda_units.cpp index 6beda86286..a835cebcd5 100644 --- a/common/eda_units.cpp +++ b/common/eda_units.cpp @@ -458,6 +458,28 @@ wxString EDA_UNIT_UTILS::UI::MessageTextFromValue( const EDA_IU_SCALE& aIuScale, text.Printf( format, value ); + // Check if the formatted value shows only zeros but the actual value is non-zero + // If so, use scientific notation instead + if( value != 0.0 ) + { + bool showsOnlyZeros = true; + + // Check if the text contains only zeros (allowing for decimal point, minus sign, etc.) + for( auto ch : text ) + { + if( ch >= '1' && ch <= '9' ) + { + showsOnlyZeros = false; + break; + } + } + + if( showsOnlyZeros ) + { + text.Printf( wxT( "%.3e" ), value ); + } + } + // Trim to 2-1/2 digits after the decimal place for short-form mm if( short_form && aUnits == EDA_UNITS::MM ) {