1 #!/bin/bash 2 a=38 3 b=99 4 5 percent_1=$(printf "%d%%" $((a*100/b))) 6 # 或者 7 percent_2=`awk 'BEGIN{printf "%.1f%%\n",('$a'/'$b')*100}'` 8 # 保留1位小数,四舍五入 9 echo $percent_1 10 echo $percent_2
结果为:
1 percent_1=38% 2 percent_2=38.4%