in reply to RE: RE: Convert seconds into a formatted ddd:hh:mm:ss string
in thread Convert seconds into a formatted ddd:hh:mm:ss string

If you want to be on the (numerically-) safe side, you can do this:
$s=$t % 60; $t=($t-$s)/60; $m=$t % 60; $t=($t-$m)/60; $h=$t % 24; $d=($t-$h)/24; $out=sprintf "%03d:%02d:%02d:%02d\n", $d,$h,$m,$s; $out=~s/^0+:|00://g;

Which is using only integers (assuming $t is integral)

Replies are listed 'Best First'.
RE: RE: RE: RE: Convert seconds into a formatted ddd:hh:mm:ss string
by husker (Chaplain) on Aug 31, 2000 at 18:07 UTC
    Well it's not really using integers .. it's still using floating point math, but the decimal portion is always zero. You and I don't care, but the computer processes 1.0 and 1 differently internally. This will make a difference when it comes to overflow and underflow conditions, and just plain execution speed ... integer math is faster, in general.