cvs commit: perlfaq perlfaq4.pod
[email protected] (Robert Spier) 20 Sep 2003 06:33:26 -0000
| Newsgroups | perl.cvs.perlfaq |
|---|---|
| Message-ID | <[email protected]> |
cvsuser 03/09/19 23:33:26
Modified: . perlfaq4.pod
Log:
Change 21204 by jhi@kosh on 2003/09/13 06:47:23
Subject: [perl #23788] int of a fraction errors
From: "Boyd, Brooks D" (via RT) <[email protected]>
Date: 11 Sep 2003 22:38:19 -0000
Message-ID: <[email protected]>
Add a separate faq entry for int(). (Yes, a bit redundant
with the existing "why are my numbers broken" entry.)
Affected files ...
... //depot/perl/pod/perlfaq4.pod#86 edit
Revision Changes Path
1.48 +19 -1 perlfaq/perlfaq4.pod
Index: perlfaq4.pod
===================================================================
RCS file: /cvs/public/perlfaq/perlfaq4.pod,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -w -r1.47 -r1.48
--- perlfaq4.pod 25 Aug 2003 05:58:04 -0000 1.47
+++ perlfaq4.pod 20 Sep 2003 06:33:25 -0000 1.48
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq4 - Data Manipulation ($Revision: 1.47 $, $Date: 2003/08/25 05:58:04 $)
+perlfaq4 - Data Manipulation ($Revision: 1.48 $, $Date: 2003/09/20 06:33:25 $)
=head1 DESCRIPTION
@@ -27,6 +27,24 @@
printf "%.2f", 10/3;
my $number = sprintf "%.2f", 10/3;
+
+=head2 Why is int() broken?
+
+Your int() is most probably working just fine. It's the numbers that
+aren't quite what you think.
+
+First, see the above item "Why am I getting long decimals
+(eg, 19.9499999999999) instead of the numbers I should be getting
+(eg, 19.95)?".
+
+For example, this
+
+ print int(0.6/0.2-2), "\n";
+
+will in most computers print 0, not 1, because even such simple
+numbers as 0.6 and 0.2 cannot be presented exactly by floating-point
+numbers. What you think in the above as 'three' is really more like
+2.9999999999999995559.
=head2 Why isn't my octal data interpreted correctly?