@@ -6,58 +6,58 @@ |
||
6 | 6 | |
7 | 7 | class DecimalValues |
8 | 8 | { |
9 | - /** |
|
10 | - * number of decimal places to round numbers to when performing calculations |
|
11 | - * |
|
12 | - * @var integer |
|
13 | - */ |
|
14 | - protected $decimal_precision = 6; |
|
15 | - |
|
16 | - /** |
|
17 | - * number of decimal places to round numbers to for display |
|
18 | - * |
|
19 | - * @var integer |
|
20 | - */ |
|
21 | - protected $locale_precision = 6; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @param EE_Currency_Config $currency_config |
|
26 | - */ |
|
27 | - public function __construct(EE_Currency_Config $currency_config) |
|
28 | - { |
|
29 | - $this->locale_precision = $currency_config->dec_plc; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * strips formatting, rounds the provided number, and returns a float |
|
34 | - * if $round is set to true, then the decimal precision for the site locale will be used, |
|
35 | - * otherwise the default decimal precision of 6 will be used |
|
36 | - * |
|
37 | - * @param float|int|string $number unformatted number value, ex: 1234.5678956789 |
|
38 | - * @param bool $round whether to round the price off according to the locale settings |
|
39 | - * @return float rounded value, ex: 1,234.567896 |
|
40 | - */ |
|
41 | - public function roundDecimalValue($number, bool $round = false): float |
|
42 | - { |
|
43 | - $precision = $round ? $this->locale_precision : $this->decimal_precision; |
|
9 | + /** |
|
10 | + * number of decimal places to round numbers to when performing calculations |
|
11 | + * |
|
12 | + * @var integer |
|
13 | + */ |
|
14 | + protected $decimal_precision = 6; |
|
15 | + |
|
16 | + /** |
|
17 | + * number of decimal places to round numbers to for display |
|
18 | + * |
|
19 | + * @var integer |
|
20 | + */ |
|
21 | + protected $locale_precision = 6; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @param EE_Currency_Config $currency_config |
|
26 | + */ |
|
27 | + public function __construct(EE_Currency_Config $currency_config) |
|
28 | + { |
|
29 | + $this->locale_precision = $currency_config->dec_plc; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * strips formatting, rounds the provided number, and returns a float |
|
34 | + * if $round is set to true, then the decimal precision for the site locale will be used, |
|
35 | + * otherwise the default decimal precision of 6 will be used |
|
36 | + * |
|
37 | + * @param float|int|string $number unformatted number value, ex: 1234.5678956789 |
|
38 | + * @param bool $round whether to round the price off according to the locale settings |
|
39 | + * @return float rounded value, ex: 1,234.567896 |
|
40 | + */ |
|
41 | + public function roundDecimalValue($number, bool $round = false): float |
|
42 | + { |
|
43 | + $precision = $round ? $this->locale_precision : $this->decimal_precision; |
|
44 | 44 | |
45 | - return round( |
|
46 | - $number, |
|
47 | - $precision ?? $this->decimal_precision, |
|
48 | - PHP_ROUND_HALF_UP |
|
49 | - ); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Removes all characters except digits, +- and . |
|
55 | - * |
|
56 | - * @param float|int|string $number |
|
57 | - * @return float |
|
58 | - */ |
|
59 | - public function filterDecimalValue($number): float |
|
60 | - { |
|
61 | - return (float) filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
62 | - } |
|
45 | + return round( |
|
46 | + $number, |
|
47 | + $precision ?? $this->decimal_precision, |
|
48 | + PHP_ROUND_HALF_UP |
|
49 | + ); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Removes all characters except digits, +- and . |
|
55 | + * |
|
56 | + * @param float|int|string $number |
|
57 | + * @return float |
|
58 | + */ |
|
59 | + public function filterDecimalValue($number): float |
|
60 | + { |
|
61 | + return (float) filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
62 | + } |
|
63 | 63 | } |