更改内存硬盘单位自适应

This commit is contained in:
HuoWenBo
2023-07-25 11:40:54 +08:00
parent 10ae5f39f0
commit c058e03fbf
3 changed files with 51 additions and 35 deletions
+13
View File
@@ -0,0 +1,13 @@
{% macro memory_format(memory) %}
{%- if memory > 1024 ** 4 * 2 -%}
{{- (memory / 1024 ** 4) | round(2) -}}TB
{% elif memory > 1024 ** 3 * 2 %}
{{- (memory / 1024 ** 3) | round(2) -}}GB
{% elif memory > 1024 ** 2 * 2 %}
{{- (memory / 1024 ** 2) | round(2) -}}MB
{% elif memory > 1024 ** 1 * 2 %}
{{- (memory / 1024 ** 1) | round(2) -}}KB
{% else %}
{{- memory -}}B
{% endif %}
{% endmacro %}