-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
23 lines (21 loc) · 851 Bytes
/
utils.py
File metadata and controls
23 lines (21 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def format_number_gr(value, symbol=""):
"""Μορφοποίηση αριθμού σε ελληνικό στυλ: κόμμα για δεκαδικά, τελεία για χιλιάδες"""
try:
formatted = f"{value:,.2f}".replace(",", "X").replace(".", ",").replace("X", ".")
return f"{formatted} {symbol}".strip()
except Exception:
return str(value)
def parse_gr_number(x):
try:
if isinstance(x, (float, int)):
return x
return float(x.replace(".", "").replace(",", "."))
except:
return None
def format_percentage_gr(value, decimals=2):
if value is None:
return "-"
sign = "-" if value < 0 else ""
abs_val = abs(value)
formatted = f"{abs_val:,.{decimals}f}".replace(",", "#").replace(".", ",").replace("#", ".")
return f"{sign}{formatted}%"