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 <noreply@anthropic.com>
This commit is contained in:
+10
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user