--- /dev/null
+format() {
+ if [ $1 -lt 100 ]; then # round down <.1 kb
+ printf '000K'
+ elif [ $1 -lt $((10**3)) ]; then
+ printf '0%sk' $(echo "scale=1;$1 / 10^3" | bc -l)
+ elif [ $1 -lt 9950 ]; then
+ printf '%sk' $(round `echo "$1 / 10^3" | bc -l` 1)
+ elif [ $1 -lt 99500 ]; then
+ printf '0%sk' $(round `echo $1 / 10^3 | bc -l` 0)
+ elif [ $1 -lt 999500 ]; then
+ printf '%sk' $(round `echo $1 / 10^3 | bc -l` 0)
+ elif [ $1 -lt 1050000 ]; then
+ printf '%sm' $(echo `round $(echo "$1 / 10^7" | bc -l) 1`*10 | bc -l)
+ elif [ $1 -lt 9950000 ]; then
+ printf '%sm' $(round `echo "$1 / 10^6" | bc -l` 1)
+ elif [ $1 -lt 99500000 ]; then
+ printf '0%sm' $(round `echo "$1 / 10^6" | bc -l` 0)
+ elif [ $1 -lt 999500000 ]; then
+ printf '%sm' $(round `echo $1 / 10^6 | bc -l` 0)
+ elif [ $1 -lt 9950000000 ]; then
+ printf '%sg' $(round `echo $1 / 10^9 | bc -l` 1)
+ elif [ $1 -lt 99500000000 ]; then
+ printf '0%sg' $(round `echo $1 / 10^9 | bc -l` 0)
+ elif [ $1 -lt 999500000000 ]; then
+ printf '%sg' $(round `echo $1 / 10^9 | bc -l` 0)
+ else
+ printf 'fast'
+ fi
+}
+
+round() {
+ echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
+}
+
+for x in {1000..10000}; do format $(( $x * 10 )); done
+