You can't rely on the shell to have floating-point arithmetic, so use scaled arithmetic:
scale=1000
stat=920
cutoff_percent=90
if [ $((stat * 100 > cutoff_percent * scale)) -ne 0 ] ; then
echo passed
else
echo failed
fi
If need be, values like 0.920
can be scaled textually by moving the decimal point. To do this, we can use a function like this one:
scale_digits=3
scale=1000
scale()
{
local norm=$(printf "%.*f" $scale_digits "$1")
local int=${norm%.*}
local frac=${norm#*.}
case $int in
0 )
printf "%s\n" $(( 1$frac - $scale ))
;;
-0 )
printf "%s\n" $(( $scale - 1$frac ))
;;
* )
printf "%s\n" $int$frac
;;
esac
}
Examples:
$ scale 0.1
100
$ scale 0
0
$ scale 000
0
$ scale +0
0
$ scale -0
0
$ scale -00
0
$ scale 0.1
100
$ scale .1
100
$ scale -.1
-100
$ scale -.12
-120
$ scale -.001
-1
$ scale +.001
1
$ scale +0.001
1
$ scale 0.001
1
$ scale -0.001
-1
$ scale -0.001223
-1
$ scale 0.001223
1
$ scale 123.456
123456
$ scale 123.4567
123457
$ scale 1.0e3
1000000
$ scale 1.0e2
100000
$ scale 1.0e0
1000
$ scale 1.0e-1
100
$ scale 1.0e-2
10
$ scale 1.0e-3
1
I'm not using anything but POSIX shell syntax and the printf
utility. I tested with Dash and Bash. If your container has any POSIX shell and printf
, this should all work.