Skip to main content
Participating Frequently
June 8, 2011
Question

Calculation is different CF vs JS

  • June 8, 2011
  • 3 replies
  • 378 views

I have the following standard calcualation that is used to figure out a monthly payment with interest.

rate = 11;

term = 48;

price = 129747;

dpayment = 0;

crate = rate/1200;

monthly_payment = (crate+(crate/(((1+crate)^term)-1)))*(price-dpayment);

Despite seeding with the same variables, I am getting the correct value in Cold Fusion, but the wrong answer if I use this calculation in JS.

Any help?

    This topic has been closed for replies.

    3 replies

    Participating Frequently
    June 9, 2011

    Thanks

    JS =

    (crate+(crate/((Math.pow( (1+crate),term))-1)))*(price-dpayment)

    Inspiring
    June 8, 2011

    Floating point math uses approximations, so accurate results are not

    guaranteed. The way floating point number approximations are handled can be

    different in each programming language. This could be the issue, assuming

    the two results are very close. If the numbers are far apart, then one of

    the two formulas has a mistake in it.

    -Mike Chabot

    Inspiring
    June 8, 2011

    I think if you spent 5min investigating what could be wrong here, you'd've probably worked this out for yourself. I mean, even just taking out each expression and seeing what they evaluate to separately should have quickly lead you to what the difference is, and about 2min of googling would've got the solution for you.

    So here's a question.  What does the caret operator do in CF?  And what does it do in JS?

    --

    Adam