shell求两个数相除后的百分比 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% Published by 风君子 独自遨游何稽首 揭天掀地慰生平 View all posts by 风君子