diff --git a/src/Money/Amount.php b/src/Money/Amount.php index a4e9bd5..f7d1f7d 100644 --- a/src/Money/Amount.php +++ b/src/Money/Amount.php @@ -40,8 +40,8 @@ public function withMajorUnit($amount) { if (is_int($amount) || is_float($amount) || (is_string($amount) && preg_match('/^[0-9]*\.[0-9]*$/', $amount))) { $amount = (float)$amount * pow(10, $this->currency->getDigits()); - - if (floor($amount) != $amount) { +var_dump(floor($amount)); var_dump(round($amount, 6)); + if (floor($amount) != round($amount, 6)) { // Too many decimal digits for the currency. throw new UnexpectedValueException(sprintf( 'Amount has too many decimal places. Calculated minor unit %f should be an integer.', @@ -50,11 +50,11 @@ public function withMajorUnit($amount) } $clone = clone $this; - $clone->amount = (int)$amount; + $clone->setMinorUnit((int)$amount); return $clone; } else { throw new UnexpectedValueException(sprintf( - 'Amount is an unexpected data type.' + 'Major Unit must be a number.' )); } } diff --git a/src/Money/Currency.php b/src/Money/Currency.php index 8549e53..3e763e5 100644 --- a/src/Money/Currency.php +++ b/src/Money/Currency.php @@ -60,7 +60,7 @@ public function getCode() */ public function getMinorUnits() { - return ($this->all_currencies->get($this->code, 'exp')); + return ($this->all_currencies->getByAlpha3($this->code)['exp']); } /** @@ -81,6 +81,6 @@ public function getDigits() */ public function getName() { - return ($this->all_currencies->get($this->code, 'name')); + return ($this->all_currencies->getByAlpha3($this->code)['name']); } }