function ceil(){ floor=`echo "scale=0;$1/1"|bc -l ` # 向下取整 add=`awk -v num1=$floor -v num2=$1 'BEGIN{print(num1<num2)?"1":"0"}'` echo `expr $floor + $add` } #下面测试 a=3.5 b=3.0 c=-2.1 echo `ceil $a` echo `ceil $b` echo `ceil $c`
function ceil(){ floor=`echo "scale=0;$1/1"|bc -l ` # 向下取整 add=`awk -v num1=$floor -v num2=$1 'BEGIN{print(num1<num2)?"1":"0"}'` echo `expr $floor + $add` } #下面测试 a=3.5 b=3.0 c=-2.1 echo `ceil $a` echo `ceil $b` echo `ceil $c`