From 48671585dd1d449f45dbff2b042a3546a6385f26 Mon Sep 17 00:00:00 2001 From: Arda Aydin Date: Sat, 12 Sep 2026 14:10:35 +0300 Subject: [PATCH] Ensure live float values always display with a decimal point Adds _fmt_float() helper that formats 32-bit floats with :.6g precision but appends .0 when the result has no decimal point, matching Niagara and .sax file display conventions (e.g. 175.0 not 175, 0.0 not 0). Co-Authored-By: Claude Opus 4.6 --- app_state.py | 2 +- device_session.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app_state.py b/app_state.py index 641ac94..ab66fdf 100644 --- a/app_state.py +++ b/app_state.py @@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it. import configparser import os -VERSION = "0.0.0.088" +VERSION = "0.0.0.089" PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties") DEFAULT_GRID_SIZE = 10 DEFAULT_ADD_TIMESTAMP = True diff --git a/device_session.py b/device_session.py index d9141ec..1fc0865 100644 --- a/device_session.py +++ b/device_session.py @@ -13,6 +13,14 @@ import schema from sox import SoxClient, SoxComponent, TREE, CONFIG, RUNTIME, LINKS, ALL +def _fmt_float(val): + """Format a 32-bit float for display: 6 significant digits, always with a decimal point.""" + s = f"{val:.6g}" + if "." not in s and "e" not in s and "E" not in s: + s += ".0" + return s + + class DeviceSession: """High-level session manager for a live Sedona device connection.""" @@ -268,7 +276,7 @@ class DeviceSession: if name in sox_comp.values: val = sox_comp.values[name] if isinstance(val, float): - val_str = f"{val:.6g}" + val_str = _fmt_float(val) else: val_str = str(val) ET.SubElement(comp_elem, "prop", @@ -366,7 +374,7 @@ class DeviceSession: name = slot["name"] if name in sox_comp.values: raw = sox_comp.values[name] - val = f"{raw:.6g}" if isinstance(raw, float) else str(raw) + val = _fmt_float(raw) if isinstance(raw, float) else str(raw) if name in existing_props: existing_props[name].set("val", val) else: