[explorer/memory] Fix conversion of large numbers (>= 2GiB)

At least mawk uses scientific notation when using print for
numbers >=2^31 (INT_MAX of a signed 32-bit int).

`printf "%.f\n"` works around this.
This commit is contained in:
Dennis Camera 2021-08-03 19:26:55 +02:00
parent 542674dae8
commit 83fe6e9f5b

View file

@ -27,19 +27,18 @@
str2bytes() {
awk -F' ' '
$2 == "B" || !$2 { print $1 }
$2 == "kB" { print $1 * 1000 }
$2 == "MB" { print $1 * 1000 * 1000 }
$2 == "GB" { print $1 * 1000 * 1000 * 1000 }
$2 == "TB" { print $1 * 1000 * 1000 * 1000 * 1000 }
$2 == "kiB" { print $1 * 1024 }
$2 == "MiB" { print $1 * 1024 * 1024 }
$2 == "GiB" { print $1 * 1024 * 1024 * 1024 }
$2 == "TiB" { print $1 * 1024 * 1024 * 1024 * 1024 }'
$2 == "kB" { printf "%.f\n", ($1 * 1000) }
$2 == "MB" { printf "%.f\n", ($1 * 1000 * 1000) }
$2 == "GB" { printf "%.f\n", ($1 * 1000 * 1000 * 1000) }
$2 == "TB" { printf "%.f\n", ($1 * 1000 * 1000 * 1000 * 1000) }
$2 == "kiB" { printf "%.f\n", ($1 * 1024) }
$2 == "MiB" { printf "%.f\n", ($1 * 1024 * 1024) }
$2 == "GiB" { printf "%.f\n", ($1 * 1024 * 1024 * 1024) }
$2 == "TiB" { printf "%.f\n", ($1 * 1024 * 1024 * 1024 * 1024) }'
}
bytes2kib() {
set -- "$(cat)"
test "$1" -gt 0 && echo $(($1 / 1024))
awk '$0 > 0 { printf "%.f\n", ($0 / 1024) }'
}