File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
tests/Omnipay/Common/Message Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,23 @@ public function testAmountZeroString()
99
99
$ this ->assertSame ('0.00 ' , $ this ->request ->getAmount ());
100
100
}
101
101
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
+
102
119
public function testGetAmountNoDecimals ()
103
120
{
104
121
$ this ->assertSame ($ this ->request , $ this ->request ->setCurrency ('JPY ' ));
You can’t perform that action at this time.
0 commit comments