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

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

Re: CONVFMT not (always?) honoured.


From: Aharon Robbins
Subject: Re: CONVFMT not (always?) honoured.
Date: Tue, 28 Oct 2003 16:53:25 +0200

Hi. Re this:

> To: address@hidden
> From: David Jones <address@hidden>
> Subject: CONVFMT not (always?) honoured.
> Date: Tue, 28 Oct 2003 14:39:00 +0000
>
> I was going to report this against my FreeBSD's default of 3.0.6 but I

Why is FreeBSD still so far back?

> remember that you guys always want me to use the latest version.
>
> The following program should output two lines with "0.33" on shouldn't
> it?
>
> $ gawk313 'BEGIN{CONVFMT="%.2f";print (1/3)+"";a[1/3]=1;for(i in a)print i}'
> 0.333333
> 0.33
>
> Cheers,
>  drj

Nope, the behavior is correct. OFMT is still used when converting
values for `print', while CONVFMT is only for number to string conversion.

Your use of `+' forces gawk to convert "" to 0.  That number is
added to the numeric value of 1/3, which is converted by OFMT for printing.
Using straight string concatenation will get you what you want:

        $ gawk 'BEGIN { CONVFMT="%.2f" ; print (1/3)""
        > a[1/3]=1 ; for(i in a)print i}'
        0.33
        0.33

HTH,

Arnold




reply via email to

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