Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r20329: LJSUP-9908

Committer: ailyin
LJSUP-9908
A   trunk/cgi-bin/LJ/NumberUtil.pm
Added: trunk/cgi-bin/LJ/NumberUtil.pm
===================================================================
--- trunk/cgi-bin/LJ/NumberUtil.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/NumberUtil.pm	2011-10-14 14:25:15 UTC (rev 20329)
@@ -0,0 +1,23 @@
+package LJ::NumberUtil;
+use strict;
+use warnings;
+
+use base qw( Exporter );
+our @EXPORT_OK = qw( round );
+
+use POSIX;
+
+use constant ROUND_HALF => 0.50000000000008;
+
+# this is stolen from Math::Round on CPAN
+sub round {
+    my ($num) = @_;
+
+    if ( $num >= 0 ) {
+        return int POSIX::floor( $num  + ROUND_HALF );
+    } else {
+        return int POSIX::ceil( $num - ROUND_HALF );
+    }
+}
+
+1;

Tags: ailyin, andy, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 1 comment