"""Display grid of numeric options: one decimal place, for the stored value and the text alike.""" from dataclasses import dataclass @dataclass(frozen=True) class Format: def value(self, value): """Round to the displayed decimal (same rounding as text), normalizing signed zero: stored value == shown value.""" if isinstance(value, list): return [self.value(x) for x in value] rounded = float(f"{value:.1f}") return 0. if rounded == 0 else rounded def text(self, value): """Plain decimal with one digit after the point (options are already quantized), also per vector component.""" if isinstance(value, list): return "[" + ", ".join(self.text(x) for x in value) + "]" text = f"{value:.1f}" return "0.0" if text == "-0.0" else text