Bash Multiplying Decimal to int

后端 未结 5 1791
花落未央
花落未央 2020-12-30 09:10

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

T=\"$((PRICE*QTY))\"|bc; gives line 272: 12.

5条回答
  •  礼貌的吻别
    2020-12-30 10:09

    var=$(echo "scale=2;$PRICE*$QTY" |bc)
    

    You can also use awk

    awk -vp=$PRICE -vq=$QTY 'BEGIN{printf "%.2f" ,p * q}'
    

提交回复
热议问题