You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unless I am doing something wrong, the following seems incorrect:
Custom conversion of 0.36 EUR to GBP using an exchange rate of 1.10 EUR to 1 GBP. To get the conversion ratio going EUR to GBP we do:
1 / 1.10 = 0.90909090909 (or 0.91 as it comes out).
Then the ->convert function is taking the ->amount (36 - cents) value of 0.36 (EUR).
And doing the following: 0.36 * 0.91 = 32.76 which is correct technically, except we are converting pence here so you cannot have 32.76 pence, it should round up to 33pence.
The ->round() method is checking for the precision of GBP via $this->currency->getPrecision() and returning it at 2 decimal places for GBP which would be correct if we were dealing with pounds, but we're not. It should be 0.
Returning getAmount(true) to force rounding is not working as it is doing the same check as above.
I am likely doing something incorrectly, any ideas or is this a bug?
The text was updated successfully, but these errors were encountered:
If the converted amount result is less than the subunit, it breaks.
This fixes it but I don't know if somewhere else I have managed to cause an error, I don't think so.
/**
* @psalm-suppress ArgumentTypeCoercion
*/
public function round(int|float $amount, int $mode = self::ROUND_HALF_UP): float
{
$this->assertRoundingMode($mode);
$precision = ($amount < $this->currency->getSubunit()) ? 0 : $this->currency->getPrecision();
return round($amount, $precision, $mode);
}
Unless I am doing something wrong, the following seems incorrect:
Custom conversion of 0.36 EUR to GBP using an exchange rate of 1.10 EUR to 1 GBP. To get the conversion ratio going EUR to GBP we do:
1 / 1.10 = 0.90909090909 (or 0.91 as it comes out).
Then the ->convert function is taking the ->amount (36 - cents) value of 0.36 (EUR).
And doing the following: 0.36 * 0.91 = 32.76 which is correct technically, except we are converting pence here so you cannot have 32.76 pence, it should round up to 33pence.
The ->round() method is checking for the precision of GBP via $this->currency->getPrecision() and returning it at 2 decimal places for GBP which would be correct if we were dealing with pounds, but we're not. It should be 0.
Returning getAmount(true) to force rounding is not working as it is doing the same check as above.
I am likely doing something incorrectly, any ideas or is this a bug?
The text was updated successfully, but these errors were encountered: