Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Multiplying Decimal to int

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?

like image 261
svenus Avatar asked Jul 19 '10 09:07

svenus


1 Answers

You can use mul=0.8 exp=200 texp=awk -vp=$mul -vq=$exp 'BEGIN{printf "%.2f" ,p * q}'

Hope this is going to work.

like image 85
vijayw Avatar answered Sep 28 '22 14:09

vijayw