Completed
Pull Request — master (#6)
by
unknown
02:56
created

MathFuncs::roundUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace FinanCalc\Utils {
4
5
    use FinanCalc\Constants\Defaults;
6
7
    /**
8
     * Class MathFuncs
9
     * @package FinanCalc\Utils
10
     */
11
    class MathFuncs
12
    {
13
        /**
14
         * @param $leftOperand
15
         * @param $rightOperand
16
         * @return string
17
         */
18
        public static function add($leftOperand, $rightOperand)
19
        {
20
            return bcadd($leftOperand, $rightOperand, Defaults::MONEY_DECIMAL_PLACES_PRECISION);
21
        }
22
23
        /**
24
         * @param $leftOperand
25
         * @param $rightOperand
26
         * @return string
27
         */
28
        public static function sub($leftOperand, $rightOperand)
29
        {
30
            return bcsub($leftOperand, $rightOperand, Defaults::MONEY_DECIMAL_PLACES_PRECISION);
31
        }
32
33
        /**
34
         * @param $leftOperand
35
         * @param $rightOperand
36
         * @return string
37
         */
38
        public static function mul($leftOperand, $rightOperand)
39
        {
40
            return bcmul($leftOperand, $rightOperand, Defaults::MONEY_DECIMAL_PLACES_PRECISION);
41
        }
42
43
        /**
44
         * @param $leftOperand
45
         * @param $rightOperand
46
         * @return string
47
         */
48
        public static function div($leftOperand, $rightOperand)
49
        {
50
            return bcdiv($leftOperand, $rightOperand, Defaults::MONEY_DECIMAL_PLACES_PRECISION);
51
        }
52
53
        /**
54
         * @param $leftOperand
55
         * @param $rightOperand
56
         * @return string
57
         */
58
        public static function pow($leftOperand, $rightOperand)
59
        {
60
            return bcpow($leftOperand, $rightOperand, Defaults::MONEY_DECIMAL_PLACES_PRECISION);
61
        }
62
63
        /**
64
         * @param $leftOperand
65
         * @param $rightOperand
66
         * @return int
67
         */
68
        public static function comp($leftOperand, $rightOperand)
69
        {
70
            return bccomp($leftOperand, $rightOperand, Defaults::MONEY_DECIMAL_PLACES_PRECISION);
71
        }
72
73
        /**
74
         * @param $roundedNumber
75
         * @param $precision
76
         * @return string
77
         */
78
        public static function round($roundedNumber, $precision = 2)
79
        {
80
            return (string)number_format((float)$roundedNumber, $precision);
81
        }
82
        
83
         /**
84
         * @param $roundedNumber
85
         * @param $precision
86
         * @return string
87
         */
88
        public static function roundUp($roundedNumber, $precision = 2) 
89
        {
90
            return (string)ceil((float)$roundedNumber * pow(10, $precision)) / pow(10, $precision);
91
        }
92
        
93
        /**
94
         * @param $roundedNumber
95
         * @param $precision
96
         * @return string
97
         */
98
        public static function roundDown($roundedNumber, $precision = 2) 
99
        {
100
            return (string)floor((float)$roundedNumber * pow(10, $precision)) / pow(10, $precision);
101
        }
102
    }
103
}
104