From bba50c6b0da13c216e5d8b52a3d184b2a54043b1 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 7 Jul 2016 16:47:22 +1000 Subject: [PATCH] * Subtitle::Utils : add round() --- lib/Subtitle/Utils.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Subtitle/Utils.pm b/lib/Subtitle/Utils.pm index 266bab8..7ccde74 100644 --- a/lib/Subtitle/Utils.pm +++ b/lib/Subtitle/Utils.pm @@ -8,6 +8,7 @@ use base 'Exporter'; our @EXPORT_OK = qw( chomp_all strip_bom trim make_timing parse_timing + round ); our %EXPORT_TAGS = ( @@ -15,7 +16,6 @@ our %EXPORT_TAGS = ( timing => [qw(make_timing parse_timing)], ); - ## string sunctions sub chomp_all { @@ -75,6 +75,13 @@ sub parse_timing { return $time; } +## misc + +sub round { + my ($value, $n) = @_; + return sprintf "%.${n}f", $value; +} + 1; =pod @@ -127,4 +134,13 @@ Takes string like "HH:MM:SS.MSEC" and returns float number of seconds On parse error returns -1 +=head1 FUNCTIONS / MISC + +=head2 C + + say round(3.6, 0); # 4 + say round(3.6, 1); # 4.1 + +Self-descriptive + =cut