If you don't care where you round to 0 or to nearest, just truncate:
$time =~ s/\..*//;
If you know the time has formate "HH:MM:SS.FRACTION" (that is, you always have 2 digits for hours, minutes, seconds), you can also do:
substr $time, 8, -1, ""; # Or
$time = substr $time, 0, 8;
| [reply] [d/l] [select] |
s/(.\....)\z/ sprintf "%.0f", $1 /es;
| [reply] [d/l] |
Just add half a second to the time, then truncate to the second.
use DateTime::Format::Strptime qw();
DateTime::Format::Strptime
->new(pattern => '%T.%N')
->parse_datetime('15:59:57.203')
->add(nanoseconds => 0.5 * 1000 * 1000 * 1000)
->truncate(to => 'second')
->strftime('%T');
# returns '15:59:57'
DateTime::Format::Strptime
->new(pattern => '%T.%N')
->parse_datetime('15:59:57.703')
->add(nanoseconds => 0.5 * 1000 * 1000 * 1000)
->truncate(to => 'second')
->strftime('%T');
# returns 15:59:58
| [reply] [d/l] |