awk not rounding with OFMT and $0
问题 I'm printing an array with 100 columns and I would like all columns to have 2 decimals. I would like to use print $0 and not have to individually specify the format for all columns. OFMT does seen to work with $0: echo '0.77767686 0.76555555 0.6667667 0.77878878' |awk '{CONVFMT="%.2g";OFMT="%.2g";print ($0+0);print ($0+0)"";print $0}' Results: 0.78 0.78 0.77767686 0.76555555 0.6667667 0.77878878 回答1: Note that all input is treated as strings until implicitly converted by how it is used. OFMT