bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] string misinterpretation


From: Aharon Robbins
Subject: Re: [bug-gawk] string misinterpretation
Date: Tue, 30 Apr 2013 22:47:58 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Hi. Thank you for taking the time to send in a report.

Davide Brini's answers and links were correct - the result of substr()
is a string and must be converted to a number in order to get correct
numerical comparisons.  As mentioned, adding zero is the usual way to
convert to numeric, but multiplying by 1 works just as well.

Thanks,

Arnold

> From: "Love, Mr. Gary, Contractor, Code 7542" <address@hidden>
> To: "'address@hidden'" <address@hidden>
> Date: Mon, 29 Apr 2013 15:20:37 -0700
> Subject: [bug-gawk] string misinterpretation
>
> Developers,
>
> I encountered a problem when a value is extracted from a field using
> the substr function and is then used in a conditional numeric test.
> The test fails unless I multiple the substr value by 1.0 because the
> parser thinks the value is a string.
> 
> The attached code and data file demonstrate the problem. The workaround
> for the problem is to change line 5
> From:
>                          incrm=substr($0,191,14)
> To:
>                          incrm=1.0*substr($0,191,14)
>
> Gary G. Love (SAIC)
> Senior Scientist
> Marine Meteorology Division
> Naval Research Laboratory
> Monterey, CA 93943
> 831-656-4767



reply via email to

[Prev in Thread] Current Thread [Next in Thread]