If you have Qalculate installed ! (which, by the way, is surprising) Theres an easy trick:
human_readable="$( qalc -t set "precision $precision" "${in_bytes}B" )"
Example:
$ qalc -t -set "precision 3" 5264334820B 5.26 GB
This is a very powerful tool for working with shells, because it even simplifies formulas, solves for the unknown, and much more.
$ qalc -t "e^(i*x)=-1" x = 3.1415927
If you want a simpler and less difficult solution, look at my other answer.
Evi1M4chine Dec 12 '13 at 12:28 2013-12-12 00:28
source share