-
Notifications
You must be signed in to change notification settings - Fork 44
/
utils.py
34 lines (32 loc) · 803 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def str_number(num):
if num > 1e14:
return f"{num/1e12:.0f}T"
elif num > 1e12:
return f"{num/1e12:.1f}T"
elif num>1e11:
return f"{num/1e9:.0f}G"
elif num > 1e9:
return f"{num/1e9:.1f}G"
elif num > 1e8:
return f"{num/1e6:.0f}M"
elif num > 1e6:
return f"{num/1e6:.1f}M"
elif num > 1e5:
return f"{num/1e3:.0f}K"
elif num > 1e3:
return f"{num/1e3:.1f}K"
elif num >= 1:
return f"{num:.1f}"
else:
return f"{num:.2f}"
def str_number_time(num):
if num >= 1:
return f"{num:.1f}"
elif num > 1e-3:
return f"{num*1e3:.1f}m"
elif num > 1e-6:
return f"{num*1e6:.1f}u"
elif num > 1e-9:
return f"{num*1e9:.1f}n"
else:
return f"{num:.0f}"