#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Question Javascript calculation problem


    I am developing a form that will allow the user to test various financial scenarios to arrive at the most favorable terms for leasing a car. I am having trouble with making a precise (two decimal places) calculation.

    Specifically, the scenario/question can be summarized like this:

    1. A person has only a single total of $500 available to apply towards both a down payment and the 10% tax on the down payment.

    2. The same $500 has to cover not only a down payment but also the tax (of 10%) on what ever amount of the $500 is then remaining for the down payment. (some car leases require the lessor to pay tax on the down payment).

    My problem is not with the Javascript, but how the calculation is made.

    Help would be gratefully appreciated!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    862
    Rep Power
    275
    the gist of it is something like this:

    var total = 500;
    var tax = 10;
    var x; //what you want to find

    x = total / (1 + (tax/100)); // x + (tax/100)*x = total

    var taxAmtTotal = (tax/100)*x;

    In this case, x = 454.55 (rounded) and the taxAmtTotal = 45.45 for a total of 500.00
    Last edited by DonR; October 26th, 2013 at 01:48 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Smile


    Thanks DonR, your answer is perfect, exactly what I was looking for.

    I really appreciate the help!

    patibob

IMN logo majestic logo threadwatch logo seochat tools logo