File tree Expand file tree Collapse file tree 1 file changed +30
-9
lines changed Expand file tree Collapse file tree 1 file changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -54,15 +54,36 @@ def short_numeric_filter(value):
54
54
"""
55
55
Get the abbreviated numeric value.
56
56
"""
57
- if value < 1000 :
58
- return f"{ value :.0f} "
59
- if value < 1000000 :
60
- return f"{ value / 1000 :.1f} K"
61
- if value < 1000000000 :
62
- return f"{ value / 1000000 :.1f} M"
63
- if value < 1000000000000 :
64
- return f"{ value / 1000000000 :.1f} B"
65
- return f"{ value / 1000000000000 :.1f} T"
57
+ units = [
58
+ "" ,
59
+ "K" ,
60
+ "M" ,
61
+ "B" ,
62
+ "T" ,
63
+ "Qa" ,
64
+ "Qi" ,
65
+ "Sx" ,
66
+ "Sp" ,
67
+ "O" ,
68
+ "N" ,
69
+ "D" ,
70
+ "UD" ,
71
+ "DD" ,
72
+ "TD" ,
73
+ "QaD" ,
74
+ "QiD" ,
75
+ "SxD" ,
76
+ "SpD" ,
77
+ "OD" ,
78
+ "ND" ,
79
+ "V" ,
80
+ ]
81
+ i = 0
82
+ mantissa = value
83
+ while mantissa >= 1000 :
84
+ mantissa /= 1000
85
+ i += 1
86
+ return f"{ mantissa :.3g} { units [i ]} " if value >= 1000 else f"{ value :.0f} "
66
87
67
88
68
89
app .jinja_env .filters ["short_numeric" ] = short_numeric_filter
You can’t perform that action at this time.
0 commit comments