Hi,
I´m doing a script where a take this value:
:local rx [/interface ethernet get ether1-WAN driver-rx-byte];
and have a value like that: 2 718 228 259 721
how can I format $rx to print the value in GB??
I try with:
:set $rx2 ($rx / 1024*1024);
but doesn´t works…
any idea??
thanks in advance!!
wimpy
2
Hallo,
I use a function human (see below) to convert integers into human-readable format (KiB, MiB, GiB) in a couple of my scripts.
:local human do={
:local input $1; :local q; :local r; :local output;
:if ($input<1024) do={:set output "$input B"} else={
:if ($input<1048576) do={:set q ($input/1024); :set r ($input-$q*1024); :set r ($r/102); :set output "$q.$r KiB"} else={
:if ($input<1073741824) do={:set q ($input/1048576); :set r ($input-$q*1048576); :set r ($r/104858); :set output "$q.$r MiB"} else={
:set q ($input/1073741824); :set r ($input-$q*1073741824); :set r ($r/107374182); :set output "$q.$r GiB"
}}}
:return [$output]
}
Regards.
neocec
3
how call to this function??
i try a couple of cases but none of them works.
thanks a lot !