Linux Shell中浮点运算方式

用bc或awk

$a=3.4 b=345.3

echo "scale=4;$a*$b/2"|bc

587.0100

$echo $a*$b/2|bc -l

587.01000000000000000000

$awk 'BEGIN{printf '$a'*'$b'/2}'

587.01

相关推荐