DreamT has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Why does $test3 become 14 in the example below? I suspect that it is related to What Every Computer Scientist Should Know About Floating-Point Arithmetic in some way. But, should an int on a value that's already an integer be affected by that?
my $test = 1.15; my $test2 = ($test - 1) * 100; my $test3 = int($test2); print "test2: $test2\n"; print "test3: $test3\n";

Replies are listed 'Best First'.
Re: Strange int behaviour?
by BrowserUk (Patriarch) on Mar 10, 2015 at 09:20 UTC

    Does this explain it for you?

    printf "%.17f\n", 1.15 - 1;; 0.14999999999999991

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
      Yes, indeed:) Thank you!