转换指数函数和取整的数字在BASH [英] Convert exponentials and rounding numbers in BASH
本文介绍了转换指数函数和取整的数字在BASH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个文件
1.5000000000E-01 7.5714285714E+00 4.0000000000E-01
2.5000000000E-01 7.5714285714E+00 4.0000000000E-01
和我要将其转换成类似
0.15 7.57 0.40
我的意思是我想的数字是,只有2位小数,而不是成为指数。我想使用bash!
i mean i want the numbers to be with only 2 decimals and not to be exponential. I want to use bash!
推荐答案
使用的printf
与 AWK
:
$ awk '{printf "%.2f %.2f %.2f\n",$1,$2,$3}' file
0.15 7.57 0.40
0.25 7.57 0.40
由于更多的领域你想像循环:
Given more fields you would want to loop like:
$ awk '{for(i=1;i<=NF;i++)printf "%.2f ",$i;print "\n"}' file
0.15 7.57 0.40
0.25 7.57 0.40
这篇关于转换指数函数和取整的数字在BASH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文