通常情况下,我们在shell中的运算都是忽略小数点儿后面的部分的,例如:
BL685-022:/usr/local/nagios/libexec # echo "0.8/0.3" |bc
2
可是如果想现实小数点后面的部分,怎么做呢,看下面:
BL685-022:/usr/local/nagios/libexec # echo "scale=2;0.8/0.3"|bc
2.66
BL685-022:/usr/local/nagios/libexec # echo "scale=3;0.8/0.3"|bc
2.666
scale指定了显示小数点后面几位,简单吧!以此类推,你可以做加减乘除
BL685-022:/usr/local/nagios/libexec # echo "scale=5;0.8*0.3"|bc
.24
BL685-022:/usr/local/nagios/libexec # echo "scale=5;0.8+0.3"|bc
1.1
BL685-022:/usr/local/nagios/libexec # echo "scale=5;0.8-0.3"|bc
.5
BL685-022:/usr/local/nagios/libexec # echo "scale=5;0.8/0.3"|bc
2.66666
阅读(1857) | 评论(0) | 转发(0) |