bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: gawk bug in reporting formatted numbers


From: Aharon Robbins
Subject: Re: gawk bug in reporting formatted numbers
Date: Fri, 12 Aug 2005 13:47:39 +0300

Greetings. I am behind in catching up on my mail. I think
several answers to this were posted already.

You should remember that floating point math can produce weird
results. You'll have better results using more digits and
the %g format.

Also, if you're really using gawk 3.0.0, you are woefully
out-of-date; that version is almost 9 years old!  Gawk 3.1.5 will
be appearing on the GNU ftp site shortly.

Hope this helps,

Arnold

> Date: Mon, 01 Aug 2005 18:29:20 -0700
> From: fuad badrieh <address@hidden>
> Subject: gawk bug in reporting formatted numbers
> To: address@hidden
>
> Hello:
>
> how come the following program
>
> echo "0.2625e-6" | gawk 'BEGIN{OFMT="%9.3f"}{print $1*1e6}'
>
> prints
>
> 0.262
>
> and not 0.263?  The 25 should have been rounded to 3.
>
> I am using gawk 3.0, patchlevel 0, on SunOS 5.8.
>
>
>
> P.S
> If I run the same thing through a C program it does print 0.263
>
> #include <stdio.h>
>
> int main() {
> float x=0.2625e-6;
> printf("%9.3f\n", x*1e6);
> }
>
> Thanks,
> Fuad




reply via email to

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