Skip to content

Commit e1bb549

Browse files
committed
Fixes to currency and amount (but don't use these anyway - use moneyphp/money).
1 parent ad27549 commit e1bb549

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Money/Amount.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function withMajorUnit($amount)
4040
{
4141
if (is_int($amount) || is_float($amount) || (is_string($amount) && preg_match('/^[0-9]*\.[0-9]*$/', $amount))) {
4242
$amount = (float)$amount * pow(10, $this->currency->getDigits());
43-
44-
if (floor($amount) != $amount) {
43+
var_dump(floor($amount)); var_dump(round($amount, 6));
44+
if (floor($amount) != round($amount, 6)) {
4545
// Too many decimal digits for the currency.
4646
throw new UnexpectedValueException(sprintf(
4747
'Amount has too many decimal places. Calculated minor unit %f should be an integer.',
@@ -50,11 +50,11 @@ public function withMajorUnit($amount)
5050
}
5151

5252
$clone = clone $this;
53-
$clone->amount = (int)$amount;
53+
$clone->setMinorUnit((int)$amount);
5454
return $clone;
5555
} else {
5656
throw new UnexpectedValueException(sprintf(
57-
'Amount is an unexpected data type.'
57+
'Major Unit must be a number.'
5858
));
5959
}
6060
}

src/Money/Currency.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getCode()
6060
*/
6161
public function getMinorUnits()
6262
{
63-
return ($this->all_currencies->get($this->code, 'exp'));
63+
return ($this->all_currencies->getByAlpha3($this->code)['exp']);
6464
}
6565

6666
/**
@@ -81,6 +81,6 @@ public function getDigits()
8181
*/
8282
public function getName()
8383
{
84-
return ($this->all_currencies->get($this->code, 'name'));
84+
return ($this->all_currencies->getByAlpha3($this->code)['name']);
8585
}
8686
}

0 commit comments

Comments
 (0)