in reply to Perl 5 numeric type and simplifications

I'm interested in knowing if this is always the case (can I rely on this behaviour of simplifying the number?)

The Perl Cookbook says "When Perl is told to print a floating-point number but not told the precision, it automatically rounds that number to however many decimal digits of precision that your machine supports." So when you state the question so generally, then I would say that I wouldn't rely on it, and I would use e.g. int or sprintf (or, if you wanted to trade precision for performance, bignum). See also What Every Programmer Should Know About Floating-Point Arithmetic.

  • Comment on Re: Perl 5 numeric type and simplifications