XP is just a number | |
PerlMonks |
Re: int() function (updated)by LanX (Saint) |
on Oct 24, 2020 at 11:31 UTC ( [id://11123118]=note: print w/replies, xml ) | Need Help?? |
Perl does an internal magic error correction/guessing when printing a number like 195.999999...etc to compensate rounding errors on the last digits. (This of course in binary and not decimal representation) I think that's why it prints $x1 as 196. I'll check as soon my laptop is up and running.
updateas I thought, it's compensating the rounding error from not being able to accurately represent 0.15 in a based 2 floating number:
There is an easy workaround , avoid the decimal point when calculating and divide at the very end.
see also Humans have too many fingers
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|