#!/bin/bash a=38 b=99 percent_1=$(printf "%d%%" $((a*100/b))) # 或者 percent_2=`awk 'BEGIN{printf "%.1f%%\n",('$a'/'$b')*100}'` # 保留1位小数,四舍五入 echo $percent_1 echo $percent_2
percent_1=38%
percent_2=38.4%
#!/bin/bash a=38 b=99 percent_1=$(printf "%d%%" $((a*100/b))) # 或者 percent_2=`awk 'BEGIN{printf "%.1f%%\n",('$a'/'$b')*100}'` # 保留1位小数,四舍五入 echo $percent_1 echo $percent_2
percent_1=38%
percent_2=38.4%