2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-16 23:06:05 +00:00

Math.pm: Added round function within a package

git-svn-id: https://svn.fhem.de/fhem/trunk@27076 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
sidey79 2023-01-17 21:59:23 +00:00
parent 938b6848a3
commit a290fca4a5

View File

@ -0,0 +1,72 @@
# $Id$
package FHEM::Core::Utils::Math;
use strict;
use warnings;
use utf8;
use Carp qw(croak carp);
use Time::HiRes;
use version; our $VERSION = qv('1.0.0');
use Exporter qw(import);
#our @EXPORT_OK = qw();
sub round
{
my $number = shift // carp q[No number specified] && return;
my $decimalPoint = shift // carp q[No number of decimal points specified] && return;
return sprintf("%.${decimalPoint}f",$number);
}
1;
__END__
=head1 NAME
FHEM::Core::Utils::Math - Perl Module to provide calculation utilitys
=head1 VERSION
This document describes FHEM::Core::Utils::Math version 1.0
=head1 SYNOPSIS
use FHEM::Core::Utils::Math;
=head1 DESCRIPTION
# round a given number to specified number of digits
FHEM::Core::Utils::Math::round($number,3);
=head1 EXPORT
The following functions are exported by this module:
none
=back
=head1 NOTES
round isn't exported per default, because there are already two perl packages, wich can export round (POSIX and Math::round)
To be sure, which round funtion is used, it is savest to not export round and use it withhin is package name. So no problems are caused, if somewhere POSIX or math::round is used, which overrides round in main.
=head1 BUGS AND LIMITATIONS
=head1 AUTHOR
Sidey79
=head1 LICENSE
FHEM::Core::Utils::Math is released under the same license as FHEM.
=cut