Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: compare num...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 8 Topic 2186 of 2241
Post > Topic >>

Re: compare numbers behaves strange...

by Ben <benoit.bardet@[EMAIL PROTECTED] > Mar 12, 2008 at 07:05 AM

On 12 mar, 14:40, di98mase <di98m...@[EMAIL PROTECTED]
> wrote:
> Hi
>
> I have a file with numbers in it. My program reads the values and
> compare them and depending on the value I increment a counter. what I
> have seen is that the evaluation fails. This is an extract of my
> numbers:
>
> 7
> 7
> 7
> 34
> 92
> 111
> 294
> 121
> 142
>
> This is parts of my program that checks the value (ms) read from the
> file and increments the counters
>
> =A0 =A0 =A0 if( ms =3D=3D 18) t18++;
> =A0 =A0 =A0 if( ms =3D=3D 19) t19++;
> =A0 =A0 =A0 if( ms >=3D 20 && ms < 30)
> =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0print ms;
> =A0 =A0 =A0 =A0 =A0t20++;
> =A0 =A0 =A0 }
> =A0 =A0 =A0 if( ms >=3D 30 && ms < 40) t30++;
> =A0 =A0 =A0 if( ms >=3D 40 && ms < 50) t40++;
> =A0 =A0 =A0 if( ms >=3D 50 && ms < 60) t50++;
> =A0 =A0 =A0 if( ms >=3D 60 && ms < 70) t60++;
>
> As you can see I dont have any numbers between 20 and 30 but I still
> get an increment for the t20 counter. When I print the value it is
> "294". Why do I have this behaviour?

You should probably do like this :

ms2 =3D int(ms/10)
Tab[ms2]++

# Having the result
END {
  for ( x in Tab ) {
    print x "\t" Tab[x]

}




 8 Posts in Topic:
compare numbers behaves strange...
di98mase <di98mase@[EM  2008-03-12 06:40:05 
Re: compare numbers behaves strange...
Ben <benoit.bardet@[EM  2008-03-12 07:05:40 
Re: compare numbers behaves strange...
Luuk <Luuk@[EMAIL PROT  2008-03-12 15:15:03 
Re: compare numbers behaves strange...
Janis <janis_papanagno  2008-03-12 07:28:05 
Re: compare numbers behaves strange...
di98mase <di98mase@[EM  2008-03-12 07:33:25 
Re: compare numbers behaves strange...
Luuk <Luuk@[EMAIL PROT  2008-03-12 15:51:02 
Re: compare numbers behaves strange...
di98mase <di98mase@[EM  2008-03-12 08:53:01 
Re: compare numbers behaves strange...
Janis <janis_papanagno  2008-03-12 08:58:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 5:07:28 CDT 2008.