shell脚本向上取整

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`

 

posted on 2020-10-20 11:21  裸睡的猪  阅读(4480)  评论(0编辑  收藏  举报