----------------8<---------------------------------------------- I was doing successive additions of amounts using the code below: $totalamount += $currentarray[5]; This line of code was inside a loop which looped for about 4000 times and for certain amounts, the sum came out funny! eg: It added the amount 3458.11 to the total 739474.59 to give 742932.699999999( instead of the correct sum 742932.70). And then when the amount 22.17 was added to this 742932.699999999, the total became 742954.87! My code is not doing any formatting of the numbers; just the above line of code and then a print statement to write the totalamount. And if I try to add these 2 numbers in another perl program(without putting it inside the loop), it gives the correct sum. Can somebody explain what is going wrong? ----------------8<----------------------------------------------
What is going wrong? Well for starters you didnt post in plain text ; ) Actually there is nothing wrong, but you need to read up on sprintf and printf in perldoc. And perhaps even refer to perlfaq4 - Data Manipulation (Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)? ) How's the haze in Singapore? Cheers, Just in - Engineer by name, butcher by profession . . . perl -e "$_ = qx/perldoc -q japh/; s/.*\"(\w+ )(\w+ )(\w+ )\w{4}(\w+)\".*/ucfirst($1).\"in - $2\".ucfirst($3).\"us$4\"/es; print" _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs