Skip to content

Commit 529b18f

Browse files
committed
Issue #69 "sprintf" fix and extended tests.
1 parent f9bd1a0 commit 529b18f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Omnipay/Common/Message/AbstractRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public function getAmount()
335335
}
336336

337337
// Check for rounding that may occur if too many significant decimal digits are supplied.
338-
$decimal_count = strlen(substr(strrchr((string)$amount, '.'), 1));
338+
$decimal_count = strlen(substr(strrchr(sprintf('%.8g', $amount), '.'), 1));
339339
if ($decimal_count > $this->getCurrencyDecimalPlaces()) {
340340
throw new InvalidRequestException('Amount precision is too high for currency.');
341341
}

tests/Omnipay/Common/Message/AbstractRequestTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,14 @@ public function testAmountPrecision()
111111
// This is *why* PHP sets the default precision at 6.
112112
ini_set('precision', 17);
113113
$this->assertSame('67.10', $this->request->getAmount());
114+
115+
$this->assertSame($this->request, $this->request->setAmount('67.01'));
114116
$this->assertSame('67.01', $this->request->getAmount());
117+
118+
$this->assertSame($this->request, $this->request->setAmount('0.10'));
115119
$this->assertSame('0.10', $this->request->getAmount());
120+
121+
$this->assertSame($this->request, $this->request->setAmount('0.01'));
116122
$this->assertSame('0.01', $this->request->getAmount());
117123
}
118124

0 commit comments

Comments
 (0)