From 3e66e82f8e749e6565ea56b232e89a710788c102 Mon Sep 17 00:00:00 2001 From: Benjamin VAUDOUR Date: Wed, 22 Dec 2021 12:29:51 +0000 Subject: [PATCH] =?UTF-8?q?Module=20format=E2=80=AF:=20ajout=20d=E2=80=99u?= =?UTF-8?q?ne=20fonction=20de=20formatage=20des=20dates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/moi/util/format.elv | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/moi/util/format.elv b/lib/moi/util/format.elv index 65464f6..bc5d2e5 100644 --- a/lib/moi/util/format.elv +++ b/lib/moi/util/format.elv @@ -177,3 +177,27 @@ fn list {|&with-header=$true &csep=' ' &hsep='-' &recompute=$true props data| echo (line &sep=$csep $props $d) } $data } + +fn size {|size| + var u = 0 + var m = [ + &10=Kio + &20=Mio + &30=Gio + ] + while (< $u 30) { + var p = (math:pow 2 (+ $u 10)) + if (< $size $p) { + break + } + set u = (to-string (+ $u 10)) + } + if (== $u 0) { + put $size + } else { + var p = (math:pow 2 (+ $u 10)) + var e = (/ $size $p) + printf '%.1f%s' $e $m[$u] + } + +}