mesilov/moneyphp-percentage
Tiny PHP helper for applying percentage calculations to MoneyPHP money values. Useful for discounts, taxes, fees, commissions, and proportional splits while keeping monetary amounts precise and reusable across your app.
moneyphp/money library by adding percentage-based calculations (e.g., VAT, discounts, or fees), which aligns well with financial applications requiring precise arithmetic on monetary values.moneyphp/money, ensuring consistency in domain modeling for financial operations.moneyphp/money or requires percentage-based monetary logic.moneyphp/money workflows without invasive changes.moneyphp/money (≥v3.0) and PHP ≥8.0. Compatibility with other libraries (e.g., ramsey/uuid, symfony/options-resolver) is indirect but manageable.19.9% VAT) may introduce rounding errors. Mitigation: Use Money::ofExact() or custom rounding strategies.Money instances could require synchronization.moneyphp/money patterns.moneyphp/money?
bcmath) to assess value-add.Money::ofExact()).moneyphp/money-percentage (if it exists) or league/math for broader functionality.config/app.php.PropertyAccess, OptionsResolver, or Validator if used for form handling or validation.moneyphp/money First:
Money objects for all monetary values.float $price → Money::USD(100).$tax = $price * 0.19) with Percentage::of(19)->applyTo($money).$subtotal = Money::of(1000, 'USD');
$vat = Percentage::of(19)->applyTo($subtotal); // Money::of(190, 'USD')
moneyphp/money v3.0+. Downgrade may be needed for legacy apps.Money objects are serialized/deserialized correctly (e.g., via JSON or custom accessors).composer require mesilov/moneyphp-percentage.TaxCalculator, DiscountService).moneyphp/money releases.moneyphp/money for breaking changes (e.g., PHP 8.2+ features).0.1 + 0.2 !== 0.3).Money::getAmount() and Percentage::getValue() for logging/debugging.moneyphp/money’s built-in assertions (e.g., assertEquals()).Percentage with retry logic for transient failures (unlikely, but possible in high-throughput systems).19 for 19%) to avoid floating-point storage issues.Money’s getAmount() for persistence (e.g., JSON fields).| Scenario | Risk | Mitigation |
|---|---|---|
| Floating-point precision | Incorrect tax/discount amounts | Use Money::ofExact() or round to nearest cent. |
| Negative percentages | Logical errors in discounts | Validate inputs (e.g., assertGreaterThan(0)). |
| Currency mismatches | Invalid operations (e.g., USD% of EUR) | Enforce same currency in applyTo(). |
| Dependency updates | Breaking changes in MoneyPHP | Test against minor versions pre-release. |
| Serialization issues | Corrupted data on deserialization | Use Money::fromArray() or custom hydrators. |
moneyphp/money and Percentage APIs.How can I help you explore Laravel packages today?