Skip to content

Round the calculated tax amount instead of truncating it - #9

Open
loevgaard wants to merge 1 commit into
masterfrom
fix/round-calculated-tax-amount
Open

loevgaard wants to merge 1 commit into
masterfrom
fix/round-calculated-tax-amount

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Sylius\Component\Taxation\Calculator\CalculatorInterface::calculate() returns a float, and ProductVariantPricesCalculator cast it straight to int — which truncates.

Stock installs are unaffected because Sylius' DefaultCalculator happens to round() before returning. But that is an implementation detail of one implementation, not part of the interface contract, so a custom or decorated tax calculator returning e.g. 219.8 would silently shave a cent off every displayed price.

(int) round(...) is free insurance. The new test uses a tax calculator returning 219.8 and asserts 1220 rather than the 1219 truncation would produce.

Addresses the fourth bug in #5.

https://claude.ai/code/session_01P9NzuVPQGvaVR97HZFq98a

CalculatorInterface::calculate() returns a float and the result was cast
straight to int, which truncates. Sylius' DefaultCalculator happens to round
before returning so stock installs were unaffected, but the interface makes no
such promise and a custom or decorated tax calculator returning e.g. 219.8
would silently shave a cent off every price.

Claude-Session: https://claude.ai/code/session_01P9NzuVPQGvaVR97HZFq98a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant