MZSanford has asked for the wisdom of the Perl Monks concerning the following question:
The following code does not work as i would expect. I was wondering if anyone knows why 1.15*100 acts diffrent under int(). My original code is below :
use strict; my $key = 12345; my @amn = (3.95,1.15); my ($s,$s2); for (@amn) { $s += int($_*100); $s2 += $_*100; } print "Scalar 1 : $s\n"; print "Scalar 2 : $s2\n";
This prints :
Scalar 1 : 509 Scalar 2 : 510
This was tested on
- Windows 2000 running ActiveState perl 5.6.1
- Solaris (sparc) 2.8 running perl 5.8.0 and 5.5.3
- RedHat 7.4 running perl 5.6.1
A shorter version of this would be :
perl -e 'print 1.15*100,"\n",int(1.15*100),"\n"'
I know NV conversion is always open to a fudge-factor, but this seems pretty tame to be effected by that. Any help is appriciated.
from the frivolous to the serious
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: NV/IV Bug ?
by Elian (Parson) on Feb 27, 2003 at 18:42 UTC | |
by MZSanford (Curate) on Feb 27, 2003 at 18:48 UTC | |
Re: NV/IV Bug ? (a fix)
by tye (Sage) on Feb 27, 2003 at 19:35 UTC | |
Re: NV/IV Bug ?
by IlyaM (Parson) on Feb 27, 2003 at 18:47 UTC | |
Re: NV/IV Bug ?
by extremely (Priest) on Feb 27, 2003 at 18:48 UTC | |
by MZSanford (Curate) on Feb 27, 2003 at 18:52 UTC | |
Re: NV/IV Bug ?
by Steve_p (Priest) on Feb 27, 2003 at 19:18 UTC | |
Re: NV/IV Bug ?
by Anonymous Monk on Feb 27, 2003 at 18:40 UTC |
Back to
Seekers of Perl Wisdom