scripts icon indicating copy to clipboard operation
scripts copied to clipboard

si function shows wrong scale letter

Open kurahaupo opened this issue 3 years ago • 0 comments

The si function shows "M" instead of "G", "T" or "P"

I would be inclined to use a table-driven function like:

si() {
    local v=$(($1)) l=${v#-} s=' kMGPTEZY'
    ! ((l = ${#l} / 3, l>=${#s} && (l = ${#s}-1) ))
    printf '%d%s\n' "$((v * 1000 ** l))" "${s:l:l>0}"
}

kurahaupo avatar Mar 21 '21 01:03 kurahaupo