InfoLens / backend /platform /format.py
dqy08's picture
重构仓库目录;增加Propagated attribution动画;UI改进
17037b0
Raw
History Blame Contribute Delete
285 Bytes
"""数值格式化等无 I/O 纯工具。"""
import math
def round_to_sig_figs(x: float, n: int = 7) -> float:
"""将浮点数舍入为 n 位有效数字。0 或非有限值原样返回。"""
if x == 0 or not math.isfinite(x):
return x
return float(f"{x:.{n}g}")