[Chicago-talk] isolating the values to right and left of the decimal
Ted Zlatanov
tzz at lifelogs.com
Wed Jan 9 14:13:05 PST 2008
On Wed, 9 Jan 2008 13:59:23 -0800 (PST) tiger peng <tigerpeng2001 at yahoo.com> wrote:
tp> Here is my solution for fun:
tp> perl -e '$t=13.32; $t =~ s/(\d+)(\.\d+)/$1.":". (int $2*60 +
tp> .5<10?"0":"").int $2*60 + .5/e; print "$t\n"'
>> I think this is a little cleaner as a one-liner and will work with
>> $t = .32 for example:
>> perl -e'$t = 13.32; printf "%d:%d\n", $t, ($t*60)%60;'
tp> There is a small bug:
-> perl -e'$t = 13.02; printf "%d:%d\n", $t, ($t*60)%60;'
tp> 13:1
Yeah, the format could be better for human consumption:
perl -e'$t = 13.02; printf "%02d:%02d\n", $t, ($t*60)%60;'
Thanks
Ted
More information about the Chicago-talk
mailing list