summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorMichael G. Schwern <schwern@pobox.com>2001-05-29 19:51:32 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2001-05-29 20:13:54 +0000
commit1affb2ee4597bbf287e792c440907d25929aff2e (patch)
tree83b87f0b89211ac4ed9c1c5c82b5f249cd8c89b7 /pod
parentf1c689a86c4d291fc38042ab6974540507ad0175 (diff)
downloadperl-1affb2ee4597bbf287e792c440907d25929aff2e.tar.gz
Example of working in integers to avoid floating point errors
Message-ID: <20010529185132.C706@blackrider.blackstar.co.uk> p4raw-id: //depot/perl@10301
Diffstat (limited to 'pod')
-rw-r--r--pod/perlfaq4.pod5
1 files changed, 5 insertions, 0 deletions
diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod
index 069340dabd..87fd66a777 100644
--- a/pod/perlfaq4.pod
+++ b/pod/perlfaq4.pod
@@ -39,6 +39,11 @@ arbitrary-precision decimal numbers with the Math::BigFloat module
(part of the standard Perl distribution), but mathematical operations
are consequently slower.
+If precision is important, such as when dealing with money, its good
+to work with integers and then divide at the last possible moment.
+For example, work in pennies (1995) instead of dollars and cents
+(19.95) and divide by 100 at the end.
+
To get rid of the superfluous digits, just use a format (eg,
C<printf("%.2f", 19.95)>) to get the required precision.
See L<perlop/"Floating-point Arithmetic">.