I've been working on a trade log reader, the log is in CSV separated ';'. The problem that arouse, is that I'm unable to multiply integer value with float value when they are saved in variables.
The short summary of this function is that it's supposed to get a unit price and a count from each trade and add it or subtract it, depending on the operation (sell or buy),
IFS=';'
function GetOverAllProfit(){
file=$1
shift
[ ! -f "$file" ] && { echo "$file file not found"; exit 99; }
while read -r date tick oper unipri curr cnt idnt
do
if [ "$oper" == "sell" ];then
profit=$((profit - unipri * cnt))
else
profit=$((profit + unipri * cnt))
fi
done < "$file"
}
this returns error
syntax error: invalid arithmetic operator (error token is ".0"), where i presume the numberin the quotes is the resedual decinal places form the original number
i've tried
test=$(echo $a $b | awk '{printf "%4.3f\n",$cnt*$unipri}'
But it doesn't work, I may be doing something wrong. Just started learning bash/shell scripting so any suggestion is appreciated.
Thanks