From 8b61226ad526707182d32514c25984d17d22371c Mon Sep 17 00:00:00 2001 From: Lico San Date: Mon, 17 Jun 2019 14:02:05 +0200 Subject: [PATCH] Update Formula1.php --- Formula1.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Formula1.php b/Formula1.php index 923dd1b..ca4d4a8 100644 --- a/Formula1.php +++ b/Formula1.php @@ -6,8 +6,10 @@ class Formula1 { private $dual_lp_ops = ['+','-']; private $single_ops = ['+','-']; - public function __construct($formula, $params=[], $precision=0, $debug=false) { + public function __construct($formula, $params=[], $precision=null, $precision_mode=PHP_ROUND_HALF_UP) { $this->params = $params; + $this->precision = $precision; + $this->precision_mode = $precision_mode; $f = $this->replace_parenth($formula, 0); if(strrpos($f, ')')>-1) { echo('PARSING ERROR: Too many closing parenthesis !'); @@ -113,7 +115,8 @@ class Formula1 { } public function compute(){ - return($this->comp($this->tree)); + if($this->precision === null) return($this->comp($this->tree)); + else return(round($this->comp($this->tree),$this->precision, $this->precision_mode)); } }