Solved

How to prorate a yearly subscription

Posted on 2010-11-16
15
502 Views
Last Modified: 2012-06-27
Hello Experts!

I'm creating a subscription-based calculator in Java and I'm trying to figure out how to correctly prorate the value if the subscription.
My yearly subscription fee is a flat $120 per year (365 days).  If a user wants only a 6 month subscription then the cost is $60.  But let's say the subscriber signs on Jan. 15, 2011 and ends his subscription on June 30.  That's only 5 months and 15 days.  I need a formula that can correctly calculate the amount I need to charge.  In this case it would be ~$55.00.  It gets a little trickier if my user signs on Feb. 6th and ends their subscription Dec. 28.
Can anyone help?
0
Comment
Question by:Greengiants15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +2
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 34149226
Why not calculate per day?
0
 
LVL 20

Expert Comment

by:Ardhendu Sarangi
ID: 34149269
The formula you are looking for is -

120/365 * No of days

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34149274
As CEHJ has pointed out it is easier to calc the daily amount, then multiply by the number of days.
Obviously the amount per day is fuzzy due to leap years, so one month in July could cost just fractionally less on a leap year.

days in year = 1/1/next - 1/1/current
days subscribed = last - first + 1
amount to pay = days subscribed / days in year * $120
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 34149347
See below (though you would put 'PER_YEAR' as a class variable)

http://technojeeves.com/joomla/index.php/free/71-difference-between-two-dates-in-java
public static double getSub(Date d1, Date d2) {
	final double PER_YEAR = 120;
	long days = TimeDiff.getTimeDifference(d1, d2, TimeDiff.TimeField.DAY);
	return (double)(days * PER_YEAR / 365);
    }

Open in new window

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34149374
I stress again that you need the +1 in

last - first + 1

Otherwise, you will never get the full year in 1/1 - 31/12, you will be short 1 day
Not only that, a subscription for 7/7-7/7 will result in 0 days, when common sense says 1?
0
 
LVL 92

Expert Comment

by:objects
ID: 34149755
0
 

Author Comment

by:Greengiants15
ID: 34149770
All - thank so so much for your solutions.  I do have one caveat.  What if a user starts their subscription on Feb.15, 2010 and ends their subscription March 15.  Really, I should charge the user $10 since it's one month but with the formula given:
days * PER_YEAR / 365
That would be:
29 *120 / 365 = 9.53

I guess for situations like this I would have to write a separate condition to calculate something like this?
0
 
LVL 92

Expert Comment

by:objects
ID: 34149834
then you want to count the # months instead of # days

0
 

Author Comment

by:Greengiants15
ID: 34149854
objects - so are you saying that if I have a situation like this:
Start date: 2/15/2010
End date: 3/30/2010

I first have to calculate the number of months then calculate the number of days?
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 100 total points
ID: 34149864
(sidenote: Banks are happy to pay me less than 1/12 of the annual rate between 15/2 and 15/3!)

If you are not going by daily rate, then a stepped calculation may work better

Is full year? $120
Is start = end?  $120 / days in year (minimum of 1 day)
else:
d = start
months = 0
days = 0
while d < end {
  add 1 month to d
  months++
}
while d < end {
  add 1 day to d
  days++
}
calc = (months + days / 30.0) * $120 / 12

Notes:
It is possible to have 3 months 30 days which is 1 day less than 4 months in some cases, but you will charge 4 months exactly.
It is also possible to charge 27 days in feb (27/28) at 27/30 of the monthly rate.
Give some take some.
0
 
LVL 92

Expert Comment

by:objects
ID: 34149870
what you have to do depends on how you want to charge :)
0
 

Author Comment

by:Greengiants15
ID: 34150120
I want to charge $10 for a month, 120 for a year and prorate the days if it falls over a month.
0
 

Author Comment

by:Greengiants15
ID: 34150448
Is there a way to calculate the number of months?
Ex:
1/15/2010
to
6/15/2011

=

5 months
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34150481
Using months is not going to help you. They have different numbers of days
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 34150597
yes you can use the Calendar class to get the month

and you can take your start and end date and increment the month of the start until they are  both in the same month

http://helpdesk.objects.com.au/java/how-do-i-add-a-specified-number-of-months-to-a-java-date

then calculate the #days as I posted above
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question