Browse Source

* Subtitle::Utils : add round()

master
Alex 'AdUser' Z 8 years ago
parent
commit
bba50c6b0d
  1. 18
      lib/Subtitle/Utils.pm

18
lib/Subtitle/Utils.pm

@ -8,6 +8,7 @@ use base 'Exporter';
our @EXPORT_OK = qw( our @EXPORT_OK = qw(
chomp_all strip_bom trim chomp_all strip_bom trim
make_timing parse_timing make_timing parse_timing
round
); );
our %EXPORT_TAGS = ( our %EXPORT_TAGS = (
@ -15,7 +16,6 @@ our %EXPORT_TAGS = (
timing => [qw(make_timing parse_timing)], timing => [qw(make_timing parse_timing)],
); );
## string sunctions ## string sunctions
sub chomp_all { sub chomp_all {
@ -75,6 +75,13 @@ sub parse_timing {
return $time; return $time;
} }
## misc
sub round {
my ($value, $n) = @_;
return sprintf "%.${n}f", $value;
}
1; 1;
=pod =pod
@ -127,4 +134,13 @@ Takes string like "HH:MM:SS.MSEC" and returns float number of seconds
On parse error returns -1 On parse error returns -1
=head1 FUNCTIONS / MISC
=head2 C<round>
say round(3.6, 0); # 4
say round(3.6, 1); # 4.1
Self-descriptive
=cut =cut

Loading…
Cancel
Save