Kay*_*Kay 4 linux shell printf
我不能在这个命令中弄错我:
a=2
b=5
c=3
printf "%.2f\t" "'$a'+'$c'*'$b'" > ofile.txt
Run Code Online (Sandbox Code Playgroud)
我得到的值为50.00.但我应该得到17.00.
当a,b,c是浮动值时如何做到这一点?例如a = 2.4,b = 5.1和c = 3.2
printf的第二个参数被解释为字符串'2',其ascii值为50.如果要进行算术运算,请在bash中使用算术求值:
printf "%.2f\t" "$((a+b*c))" > ofile.txt
Run Code Online (Sandbox Code Playgroud)