shell中的数值计算1/3=0.33

方法1:使用bc工具,把结果printf格式化

 res=$(printf "%.5f" `echo "scale=5;1/3"|bc`)
 echo $res
0.33333

方法2:判断结果长度,是否要添0

 ab=`echo "scale=5;a=1/3;if(length(a)==scale(a)) print 0;print a"|bc`
 echo $ab
0.33333
原文地址:https://www.cnblogs.com/xkus/p/7521619.html