Skip to content

Commit

Permalink
Fixes to currency and amount (but don't use these anyway - use moneyp…
Browse files Browse the repository at this point in the history
…hp/money).
  • Loading branch information
judgej committed Mar 11, 2017
1 parent ad27549 commit e1bb549
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Money/Amount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -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.'
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Money/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand All @@ -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']);
}
}

0 comments on commit e1bb549

Please sign in to comment.