Tuni
Tuni

Reputation: 129

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?

Upvotes: 0

Views: 248

Answers (1)

James Brown
James Brown

Reputation: 37424

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)

Upvotes: 2

Related Questions