- commit
- 29f448dfa4db0427f0cc4d02f1022fb6eb3abee5
- parent
- 473d38ce3e2090d5ab3493c057f5d18b534bef00
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-07-06 10:02
smarter number formatting
Diffstat
| M | sheet/__main__.py | 7 | +++---- |
| M | sheet/term.py | 2 | +- |
2 files changed, 4 insertions, 5 deletions
diff --git a/sheet/__main__.py b/sheet/__main__.py
@@ -13,10 +13,9 @@ from .term import red 13 13 14 14 15 15 def to_cell(value: float|int|str|None|Exception, width: int) -> str:16 -1 if isinstance(value, float):17 -1 return align_right(str(value), width)18 -1 elif isinstance(value, int):19 -1 return align_right(str(value), width)-1 16 if isinstance(value, float|int): -1 17 s = f'{{:{width}.{min(width - 2, 6)}g}}'.format(value) -1 18 return align_right(s, width) 20 19 elif isinstance(value, str): 21 20 return align_left(value, width) 22 21 elif value is None:
diff --git a/sheet/term.py b/sheet/term.py
@@ -1,7 +1,7 @@ 1 1 def align_right(s, width): 2 2 if len(s) > width: 3 3 s = '###'4 -1 return ' ' + ' ' * (width - len(s) - 1) + s-1 4 return ' ' * (width - len(s)) + s 5 5 6 6 7 7 def align_left(s, width):