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:
+1
-1
@@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it.
|
|||||||
import configparser
|
import configparser
|
||||||
import os
|
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")
|
PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties")
|
||||||
DEFAULT_GRID_SIZE = 10
|
DEFAULT_GRID_SIZE = 10
|
||||||
DEFAULT_ADD_TIMESTAMP = True
|
DEFAULT_ADD_TIMESTAMP = True
|
||||||
|
|||||||
+10
-2
@@ -13,6 +13,14 @@ import schema
|
|||||||
from sox import SoxClient, SoxComponent, TREE, CONFIG, RUNTIME, LINKS, ALL
|
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:
|
class DeviceSession:
|
||||||
"""High-level session manager for a live Sedona device connection."""
|
"""High-level session manager for a live Sedona device connection."""
|
||||||
|
|
||||||
@@ -268,7 +276,7 @@ class DeviceSession:
|
|||||||
if name in sox_comp.values:
|
if name in sox_comp.values:
|
||||||
val = sox_comp.values[name]
|
val = sox_comp.values[name]
|
||||||
if isinstance(val, float):
|
if isinstance(val, float):
|
||||||
val_str = f"{val:.6g}"
|
val_str = _fmt_float(val)
|
||||||
else:
|
else:
|
||||||
val_str = str(val)
|
val_str = str(val)
|
||||||
ET.SubElement(comp_elem, "prop",
|
ET.SubElement(comp_elem, "prop",
|
||||||
@@ -366,7 +374,7 @@ class DeviceSession:
|
|||||||
name = slot["name"]
|
name = slot["name"]
|
||||||
if name in sox_comp.values:
|
if name in sox_comp.values:
|
||||||
raw = sox_comp.values[name]
|
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:
|
if name in existing_props:
|
||||||
existing_props[name].set("val", val)
|
existing_props[name].set("val", val)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user