Skip to content

Commit f9bd1a0

Browse files
committed
Issue #69 Tests that demonstrate the issue.
1 parent 1635924 commit f9bd1a0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/Omnipay/Common/Message/AbstractRequestTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ public function testAmountZeroString()
9999
$this->assertSame('0.00', $this->request->getAmount());
100100
}
101101

102+
// See https://github.com/thephpleague/omnipay-common/issues/69
103+
public function testAmountPrecision()
104+
{
105+
// The default precision for PHP is 6 decimal places.
106+
ini_set('precision', 6);
107+
$this->assertSame($this->request, $this->request->setAmount('67.10'));
108+
$this->assertSame('67.10', $this->request->getAmount());
109+
110+
// At 17 decimal places, 67.10 will echo as 67.09999...
111+
// This is *why* PHP sets the default precision at 6.
112+
ini_set('precision', 17);
113+
$this->assertSame('67.10', $this->request->getAmount());
114+
$this->assertSame('67.01', $this->request->getAmount());
115+
$this->assertSame('0.10', $this->request->getAmount());
116+
$this->assertSame('0.01', $this->request->getAmount());
117+
}
118+
102119
public function testGetAmountNoDecimals()
103120
{
104121
$this->assertSame($this->request, $this->request->setCurrency('JPY'));

0 commit comments

Comments
 (0)