Divide two variables in bash

shell parsing is useful only for integer division: var1=8 var2=4 echo $((var1 / var2)) output: 2 instead your example: var1=3 var2=4 echo $((var1 / var2)) ouput: 0 it’s better to use bc: echo “scale=2 ; $var1 / $var2” | bc output: .75 scale is the precision required

Why does Decimal.Divide(int, int) work, but not (int / int)?

int is an integer type; dividing two ints performs an integer division, i.e. the fractional part is truncated since it can’t be stored in the result type (also int!). Decimal, by contrast, has got a fractional part. By invoking Decimal.Divide, your int arguments get implicitly converted to Decimals. You can enforce non-integer division on int … Read more