From: Michael G. Schwern Date: Tue, 29 May 2001 18:51:32 +0000 (+0100) Subject: Example of working in integers to avoid floating point errors X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1affb2ee4597bbf287e792c440907d25929aff2e;p=p5sagit%2Fp5-mst-13.2.git Example of working in integers to avoid floating point errors Message-ID: <20010529185132.C706@blackrider.blackstar.co.uk> p4raw-id: //depot/perl@10301 --- diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index 069340d..87fd66a 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) to get the required precision. See L.