[英]awk compare two scientific float numbers
i have the following problem with awk: 我在awk中遇到以下问题:
code: 码:
var=1.16000e-02
size=1.10e-02
foo=$(awk -v this="${var}" -v trg="$size" 'BEGIN { out=0; if(this=trg) out=1;printf "%i", out; exit(0)}')
sh -x gives me the following statement: sh -x给我以下声明:
+ awk -v this=1.16000e-02 -v trg=1.10e-02 BEGIN { out=0; if(this=trg) out=1;printf "%i", out; exit(0)}
+ foo=1
Why is foo=1
if obviously this is not equal to trg
? 如果
foo=1
显然不等于trg
为什么还要foo=1
?
With 用
if(this=trg)
you set the value of variable trg
to the value of variable this
and that should be true, you did it yourself. 您将变量
trg
的值设置为this
变量的值,那应该是真的,您自己完成了。 You should 你应该
if(this==trg)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.