Skip to content

Commit 03e268e

Browse files
committed
Used BC Math Functions
1 parent 2130921 commit 03e268e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/Crisu83/Conversion/Quantity/Quantity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function add($quantity, $unit = null)
6363
/** @var Quantity $quantity */
6464
$quantity = new static($quantity, $unit);
6565
$quantity->to($this->unit);
66-
$this->value += $quantity->getValue();
66+
$this->value = bcadd($this->value, $quantity->getValue());
6767
return $this;
6868
}
6969

@@ -81,7 +81,7 @@ public function sub($quantity, $unit = null)
8181
/** @var Quantity $quantity */
8282
$quantity = new static($quantity, $unit);
8383
$quantity->to($this->unit);
84-
$this->value -= $quantity->getValue();
84+
$this->value = bcsub($this->value, $quantity->getValue());
8585
return $this;
8686
}
8787

@@ -106,7 +106,7 @@ public function to($unit)
106106
*/
107107
protected function convert($from, $to, $value)
108108
{
109-
return ($value * $this->getConversionRate($from)) / $this->getConversionRate($to);
109+
return bcdiv(bcmul($value, $this->getConversionRate($from)), $this->getConversionRate($to));
110110
}
111111

112112
/**

0 commit comments

Comments
 (0)