+round() {
+ echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
+}
+
+format() {
+ if [ $1 == 0 ]; then
+ printf '000K'
+ elif [ $1 -lt 999 ]; then
+ # printf '%sK' "$1";
+ printf %03d%s ${1%.*} K
+ elif [ $1 -lt 10240 ]; then
+ printf '%sM' "`echo "scale=1;$1 / 1024" | bc -l`"
+ elif [ $1 -lt 102400 ]; then
+ printf '0%sM' "$(round `echo "scale=1;$1 / 1024" | bc -l` 0)"
+ elif [ $1 -lt 1024000 ]; then
+ printf '%sM' "$(round `echo "scale=1;$1 / 1024" | bc -l` 0)"
+ else
+ printf '%sG' "$(round `echo "scale=2;$1 / 1048576" | bc -l` 1)"
+ fi
+}
+