我想计算表达式并将输出正确显示到小数点后 3 位我尝试使用以下代码但它不起作用帮助我如何在 bash 中执行此操作。
echo -e "Enter expression to calculate : \c"
read num
let a=num
printf '%f\n' "$a"
Input : 5+50*3/20 + (19*2)/7
Output : 17.000000
Desired Output : 17.929
最佳答案
使用bc
:
echo 'scale=3; 5+50*3/20 + (19*2)/7' | bc -l
输出:
17.928
关于linux - 十进制值不在 bash 中打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50167523/