diff --git a/src/UnitConverter/Calculator/AbstractCalculator.php b/src/UnitConverter/Calculator/AbstractCalculator.php index 9f35d1b8..261b6e48 100644 --- a/src/UnitConverter/Calculator/AbstractCalculator.php +++ b/src/UnitConverter/Calculator/AbstractCalculator.php @@ -24,6 +24,36 @@ */ abstract class AbstractCalculator implements CalculatorInterface { + /** + * @const int DEFAULT_PRECISION The default precision value. + */ + const DEFAULT_PRECISION = 2; + + /** + * @const int DEFAULT_ROUNDING_MODE The default rounding mode for calculators. + */ + const DEFAULT_ROUNDING_MODE = self::ROUND_HALF_UP; + + /** + * @const int ROUND_HALF_UP Makes 1.5 into 2 and -1.5 into -2. + */ + const ROUND_HALF_UP = PHP_ROUND_HALF_UP; + + /** + * @const int ROUND_HALF_DOWN Makes 1.5 into 1 and -1.5 into -1. + */ + const ROUND_HALF_DOWN = PHP_ROUND_HALF_DOWN; + + /** + * @const int ROUND_HALF_EVEN Rounds to the nearest even value. + */ + const ROUND_HALF_EVEN = PHP_ROUND_HALF_EVEN; + + /** + * @const int ROUND_HALF_ODD Rounds to the nearest odd value. + */ + const ROUND_HALF_ODD = PHP_ROUND_HALF_ODD; + /** * @var int $precision The number of decimal places that will calculated */ @@ -45,8 +75,8 @@ abstract class AbstractCalculator implements CalculatorInterface */ public function __construct (int $precision = null, int $roundingMode = null) { - $this->setPrecision(($precision ?? 2)); - $this->setRoundingMode(($roundingMode ?? PHP_ROUND_HALF_UP)); + $this->setPrecision(($precision ?? self::DEFAULT_PRECISION)); + $this->setRoundingMode(($roundingMode ?? self::DEFAULT_ROUNDING_MODE)); } public function setPrecision (int $precision): CalculatorInterface