user3429531 user3429531 - 5 months ago 9x
Bash Question

invalid arithmetic operatior

I am trying to multiply a integer value with a decimal

value = 2*1.5
. but how it gives me this error,
"invalid arithmetic operator"

I researched online and most of the solution provided is just to add that | bc behind the decimal value but however I tried it and it still doesn't work,

echo $results


try this

results=`bc <<< "scale=2; 2*1.5"`
echo $results

here scale=2 means it will consider 2 decimal places

Please don't forget "`" tilde sign which is important above