-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.php
More file actions
48 lines (44 loc) · 1.23 KB
/
globals.php
File metadata and controls
48 lines (44 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Global helpers.
*/
use Decimal\Decimal;
if (!function_exists("decimal")) {
/**
* @param string|int|\Decimal\Decimal $value
* @param int $precision
*
* @return \Decimal\Decimal The decimal value of $value, parsed to $precision.
*/
function decimal($value, int $precision = Decimal::DEFAULT_PRECISION): Decimal
{
return new Decimal($value, $precision);
}
}
if (!function_exists("is_decimal")) {
/**
* @return bool TRUE if the given value is a decimal, FALSE otherwise.
*/
function is_decimal($value): bool
{
return $value instanceof Decimal;
}
}
if (!function_exists("decimal_sum")) {
/**
* @return \Decimal\Decimal The sum of all given values, calculated to $precision.
*/
function decimal_sum($values, int $precision = Decimal::DEFAULT_PRECISION): Decimal
{
return Decimal::sum($values, $precision);
}
}
if (!function_exists("decimal_avg")) {
/**
* @return \Decimal\Decimal The average of all given values, calculated to $precision.
*/
function decimal_avg($values, int $precision = Decimal::DEFAULT_PRECISION): Decimal
{
return Decimal::avg($values, $precision);
}
}