Skip to content

Commit

Permalink
Merge pull request #31 from vaites/master
Browse files Browse the repository at this point in the history
Fixed amounts with decimals
  • Loading branch information
BenjaminPaap committed Nov 2, 2016
2 parents 2a8fe31 + 81848fe commit c47f16e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct($amount, $iban, $name)
throw new InvalidArgumentException('Using floats for amount is only possible with bcmath enabled');
}
bcscale(2);
$amount = (integer)bcmul($amount, 100);
$amount = (integer)bcmul(sprintf('%01.4F', $amount), '100');
}
$this->transferAmount = $amount;
$this->iban = $iban;
Expand Down
29 changes: 29 additions & 0 deletions tests/Unit/SumOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,35 @@ public function floatSumIsCalculatedCorrectly()
);
}

/**
* @test
*/
public function floatSumIsCalculatedCorrectlyWithNonEnglishLocale()
{
$result = setlocale(LC_ALL, 'es_ES.UTF-8', 'es_ES@UTF-8', 'spanish');

if($result == false) {
$this->markTestSkipped('spanish locale is not available');
}

$this->createDirectDebitXpathObject('19.999');
$controlSum = $this->directDebitXpath->query('//sepa:GrpHdr/sepa:CtrlSum');
$this->assertEquals('19.99', $controlSum->item(0)->textContent, 'GroupHeader ControlSum should be 19.99');

$controlSum = $this->directDebitXpath->query('//sepa:PmtInf/sepa:CtrlSum');
$this->assertEquals(
'19.99',
$controlSum->item(0)->textContent,
'PaymentInformation ControlSum should be 19.99'
);
$controlSum = $this->directDebitXpath->query('//sepa:DrctDbtTxInf/sepa:InstdAmt');
$this->assertEquals(
'19.99',
$controlSum->item(0)->textContent,
'DirectDebitTransferInformation InstructedAmount should be 19.99'
);
}

/**
* @test
*/
Expand Down

0 comments on commit c47f16e

Please sign in to comment.