# 
# Bash source file for percent computing
#
# (C) 2011-2012 Felix Hauri - felix@f-hauri.ch
# Licensed under terms of LGPL v3. www.gnu.org

# after sourcing script:
# syntaxe: percent <amount> <total>

percent() {
    local _pr100k=$((${1}00000/$2)) _floatOut;
    [ ${#_pr100k} -gt 3 ] &&
	_floatOut=${_pr100k:0:${#_pr100k}-3}.${_pr100k:${#_pr100k}-3} ||
	_floatOut=$(printf ".%03d" $_pr100k)
    printf "%.2f%%\n" $_floatOut
}

export -f percent
