Bash Multiplying Decimal to int

svenus picture svenus · Jul 19, 2010 · Viewed 28.2k times · Source

I read price from user input. When i multiply the input with int like this

T="$((PRICE*QTY))"|bc; gives line 272: 12.00: syntax error: invalid arithmetic operator (error token is ".00") or .50

depending on user input. How do i multiply these two variables and get a total with 2 decimal points?

Answer

loentar picture loentar · Jul 19, 2010

this works:


PRICE=1.1
QTY=21
RES=$(echo "scale=4; $PRICE*$QTY" | bc)
echo $RES