简体   繁体   中英

awk compare two scientific float numbers

i have the following problem with 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:

+ 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 ?

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. You should

if(this==trg)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM