Thread Floor auch für Minuswerte? (13 answers)
Opened by silbersteine at 2004-08-05 02:03

renee
 2004-08-05 09:28
#85382 #85382
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /usr/bin/perl

use strict;
use warnings;

my $var =  -440;
print "renee:\t ",clock_renee($var),"\n";
print "silbersteine: ",clock_silbersteine($var),"\n";

sub clock_renee {
   my $minutes = shift;
   my $hh = int $minutes/60;
   $minutes *=  -1 if($minutes < 0);
   my $rest = $minutes % 60;
   $rest = sprintf("%02d",$rest);
   return "$hh:$rest";
}

sub clock_silbersteine{
   my $minutes = shift;
   my $hh = int($minutes/60);
   my $rest = $minutes - $hh*60;
   if (length($rest) == 1) {$rest = "0".$rest}
   return "$hh:$rest";
}


Ausgabe:
Quote
~ 7> perl clock.pl
renee:   -7:20
silbersteine: -7:-20
\n\n

<!--EDIT|renee|1091683748-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Floor auch für Minuswerte?