Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个 awk 命令。
awk '{t1=$1/5;t2=$2/5;t3=$3/5} END{print t1" "t2" "t3}' temp1 > temp3
我想将 t1 值的数据类型更改为整数。我怎样才能做到这一点?
问候
苏
只需指定t1应格式化为整数:
t1
awk '{t1=$1/5;t2=$2/5;t3=$3/5} END{printf "%d %.6g %.6g\n", t1, t2, t3}' temp1 > temp3
这%.6g是默认格式(也在 OFMT 中保存)。
%.6g
尝试int()对值使用函数t1:
int()
int(t1)
它截断小数,只留下值的整数部分。