>>>>> "OR" == Octavian Râşniţă <orasn...@gmail.com> writes:

  OR> From: "Shawn H. Corey" <shawnhco...@gmail.com>
  >> Either the programs (not the languages) are doing their calculations
  >> in cents, not dollars or they are rounding off at a higher level
  >> than Perl. You just think they are not making errors because they're
  >> not telling you what they're really doing.

  OR> They give a different result which is a correct one so their higher
  OR> level way is prefered.

sorry to say but you still don't get it. automatically rounding numbers
is not higher level NOR correct. there is NO correct way to handle
floating numbers like that. none. nada. it is a very well known issue in
ALL programming languages that support floats. some choose convenience
solutions which may work some of the time but will screw up worse other
times. the correct solution for money has always been to use integers
for the smallest amount (e.g. cents). this will always be correct in all
languanges.

  >> If you want more accurate results, consider using bignum or bigrat
  >> (see `perldoc bignum` and `perldoc bigrat`).

  OR> That's what I needed! I found that I can use Math::BigFloat or
  OR> sprintf(), but it is ugly to manually create an object for every float
  OR> used, or round each number, but it seems that bignum it is the way to
  OR> go, and it offers more features.

and that is much slower than integers for money. much much slower.

you can choose what you want but the key point is that you make a
rational choice based on the facts, not based on some emotional reaction
to which appears more correct. this is the lesson you should learn here
more than anything else. programming is a set of logical decisions and
your code is the record of the choices you made.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to