bash
cannot handle non-integer arithmetic. It will give you the correct result as long as all the expressions are integers. So you need to avoid getting a non-integer value somewhere in your calculation.
In your case, when you are evaluating 1 / 5
, 2 / 5
etc. it creates the integer zero values in bash correspondings to some non-integer values and the results are coming out to be zero accordingly. Precedence of division and multiplication are the same and same precedent operators are always executed left to right as they are placed in the expression.
One work around will be to do the multiplication first and then the division so bash never has to handle non-integer value. The corrected expression will be,
$ max=5; for e in $(seq 1 1 $max); do percent=$(( $e*100/$max )); echo "echo $e / $max : = $percent"; done
echo 1 / 5 : = 20
echo 2 / 5 : = 40
echo 3 / 5 : = 60
echo 4 / 5 : = 80
echo 5 / 5 : = 100