[Chicago-talk] (no subject)

Joel Berger joel.a.berger at gmail.com
Fri Apr 27 21:09:20 PDT 2012


Perhaps I'm mistaken about something, but it should "round half to even".
Still, if you look up round in perlfaq4 it gives a little more information
about what you are seeing (perldoc -q round).

You may have to take its advice and implement your own rounding algorithm,
but I'm sure there must be something on CPAN for this.

Joel

On Fri, Apr 27, 2012 at 8:54 PM, Michael Potter <michael at potter.name> wrote:

> Monks,
>
> I am looking for a graceful way to round numbers.
>
> The following program
> #!/bin/perl
>
> sub myround
> {
>   my $src = shift;
>   printf("%.2f\n", $src);
> }
>
> myround("1.335");
> myround("0.335");
>
> outputs this:
> $ perl ./round.pl
> 1.33
> 0.34
>
> I know why.  It has to do with the well known side effects of using
> floating point.
>
> What I don't know is a graceful way to round.
>
> I would like to use something that already comes with perl and void
> adding any modules.
>
> --
> potter
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20120427/62ac03b0/attachment.html>


More information about the Chicago-talk mailing list