bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Bug? - print int(100*32.98)


From: arnold
Subject: Re: [bug-gawk] Bug? - print int(100*32.98)
Date: Mon, 03 Jun 2019 07:09:09 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Thanks for your note.

Robert Brandtner <address@hidden> wrote:

> Hello,
>
> Is the following result a bug or a feature?
>
> gawk 'BEGIN{print int(100*32.98)}'
> => 3297
>
> Kind regards
> Robert Brandtner

It's just the way things are. Gawk uses floating point math. 100 * 32.98
isn't quite 3298:

$ gawk 'BEGIN{printf("%.17g\n", 100*32.98)}'
3297.9999999999995

When that result is handed to int(), it gets rounded down to 3297.

HTH,

Arnold



reply via email to

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