UNIX中十进制数逻辑的比较
如果是十进制值比较,则不起作用。请调试代码并提供解决方案。请查找下面的代码 提前谢谢。。UNIX中十进制数逻辑的比较,unix,Unix,如果是十进制值比较,则不起作用。请调试代码并提供解决方案。请查找下面的代码 提前谢谢。。 i=2.4524 j=2.430 s=0.2 sub=`echo“$i-$j”| bc` 如果($sub试试这个,我想这会解决你的问题 i=2.4524 j=2.430 s=0.2 sub=`echo "$i - $j" | bc` if ( $sub le $s ) then echo "red" else echo "green"
i=2.4524
j=2.430
s=0.2
sub=`echo“$i-$j”| bc`
如果($sub试试这个,我想这会解决你的问题
i=2.4524
j=2.430
s=0.2
sub=`echo "$i - $j" | bc`
if ( $sub le $s )
then
echo "red"
else
echo "green"
fi
使用expr
:
i=2.4524
j=2.430
s=0.2
sub=`echo "$i - $j" | bc`
if expr "$sub" '<=' "$s" > /dev/null; then
echo "red"
else
echo "green"
fi
以下是一些解决方案:[[1]:[2]:
i=2.4524
j=2.430
s=0.2
sub=`echo "$i - $j" | bc`
if expr "$sub" '<=' "$s" > /dev/null; then
echo "red"
else
echo "green"
fi
if [ "`echo "$sub <= $s" | bc`" = 1 ]; then
echo "red"
else
echo "green"
fi