How do I use floating-point arithmetic in bash?

I am trying to divide two image widths in a Bash script, but bash gives me 0 as the result:

RESULT=$(($IMG_WIDTH/$IMG2_WIDTH))

I did study the Bash guide and I know I should use bc, in all examples in internet they use bc. In echo I tried to put the same thing in my SCALE but it didn’t work.

Here is the example I found in the tutorials:

echo "scale=2; ${userinput}" | bc 

How can I get Bash to give me a float like 0.5?

23 Answers
23

Leave a Comment