Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] int() function acting wierd

Expand Messages
  • Shawn Corey
    ... Congratulations. You have just stumbled across a field of study called Numerical Analysis . You be better
    Message 1 of 7 , Jan 21, 2006
    • 0 Attachment
      Mike Southern wrote:
      > I suppose to get round the problem, instead of $num = ($x * 100) you could
      > use $num = ($x * 1000000) / 1000 but is there a more elegant perl function
      > for that?

      Congratulations. You have just stumbled across a field of study called
      Numerical Analysis <http://en.wikipedia.org/wiki/Numerical_Analysis>.

      You be better off with:

      $num = int(( $x + $epsilon ) * 100 );

      where $epsilon < Error in $x


      Perl elegant? Perl is like your grandfather's garage. Sure, he kept most
      of it tidy to please your grandmother but there was always one corner
      where you could find the most amazing junk. And some days, when you were
      particularly lucky, he'd show you how it worked.


      --

      Just my 0.00000002 million dollars worth,
      --- Shawn

      "Probability is now one. Any problems that are left are your own."
      SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

      * Perl tutorials at http://perlmonks.org/?node=Tutorials
      * A searchable perldoc is available at http://perldoc.perl.org/
    Your message has been successfully submitted and would be delivered to recipients shortly.