Prorated Plan Upgrade

Medium ⏱ 12 min 55% acceptance ★★★★☆ 4.4
Mid-cycle upgrades charge only the difference for remaining days. Write proration(old_price, new_price, days_used, cycle_days) returning the charge: unused fraction of the cycle × (new − old), rounded to 2 decimals, floored at 0 (downgrades credit differently — not here).

Examples

Example 1
Input
proration(500, 900, 10, 30)
Output
266.67
Explanation

20/30 of the cycle remains: (2/3)×400.

Constraints

  • Never negative.
  • Round to 2 decimals.

Topics

Business Logicsubscription billing

Companies

StripeChargebeeZoho

Hints

Hint 1

remaining = (cycle_days - days_used) / cycle_days.

Hint 2

max(0, ...) guards downgrades.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.