Linux shell

我想实现 举例:1/3=0.33得到0.33,

尝试过bc 只能得到.33,没有0,

linux 下的shell脚本,13是变量$a$b,并能指定小数点后的位数,

 

方法1

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

 

方法2

$> 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/recognition/p/5459681.html