From 3021dd1d7d17b40e4ed56922f3de7c27335ed804 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Mon, 28 Apr 2014 17:47:33 +0545 Subject: [PATCH] Used BC Math Functions --- src/Crisu83/Conversion/Quantity/Quantity.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Crisu83/Conversion/Quantity/Quantity.php b/src/Crisu83/Conversion/Quantity/Quantity.php index 63fb4f2..a18ba99 100644 --- a/src/Crisu83/Conversion/Quantity/Quantity.php +++ b/src/Crisu83/Conversion/Quantity/Quantity.php @@ -64,7 +64,7 @@ public function add($quantity, $unit = null) $quantity = new static($quantity, $unit); /** @var Quantity $quantity */ $quantity->to($this->unit); - $this->value += $quantity->getValue(); + $this->value = bcadd($this->value, $quantity->getValue()); return $this; } @@ -83,7 +83,7 @@ public function sub($quantity, $unit = null) $quantity = new static($quantity, $unit); /** @var Quantity $quantity */ $quantity->to($this->unit); - $this->value -= $quantity->getValue(); + $this->value = bcsub($this->value, $quantity->getValue()); return $this; } @@ -108,7 +108,7 @@ public function to($unit) */ protected function convert($from, $to, $value) { - return ($value * $this->getConversionRate($from)) / $this->getConversionRate($to); + return bcdiv(bcmul($value, $this->getConversionRate($from)), $this->getConversionRate($to)); } /**