The perlfaq4 answer about floating point error should point out the
technique of working in integers and then converting to decimal at the
end.

--- pod/perlfaq4.pod    2001/05/29 17:46:32
+++ pod/perlfaq4.pod    2001/05/29 17:48:38
@@ -39,6 +39,11 @@
 (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">.  


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
I was *meant* to mount your donuts.

Reply via email to