Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 29th, 2004, 09:57 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default Might this be a logic error due to the code?

Hello all,

I must say that I have been through a lot of problems with the current project I am working on. Most of them were due to the textbook I am using. Anyways, I've gotten the page to work ok except that the Monthly Payment text box doesn't show the monthly payment correctly. When a user clicks on the Calculate button, the result should come out as $521.00. Instead, I get something like this:

$697.31890407245.


This is the code:


Code:
  function monthly(mortAmount,mortRate,mortYears) {
      var Irate=mortRate/1200
      var Pmts=mortYears*12
      var Loan=mortAmount
      return Loan * (Irate / (1 - (1 / Math.pow(1+Irate,Pmts))))
   }

  function dollarFormat(valuein) {
     var formatStr=""
     var Outdollars=""
     var decipos=valuein.indexOf(".")
     if (decipos==-1)
        decipos=valuein.length
     var dollars=valuein.substring(0,decipos)
     var dollen=dollars.length
     if (dollen>3) {
        while (dollen>0) {
              tDollars=dollars.substring(dollen-3,dollen)
              if (tDollars.length==3) {
                  Outdollars=","+tDollars+Outdollars
                   dollen=dollen-3
             } else {
                     Outdollars=tDollars+Outdollars
                    dollen=0
               }     
        }    
      if (Outdollars.substring(0,1)==",")
         dollars=Outdollars.substring(1,Outdollars.length)
      else
         dollars=Outdollars
      }
      var cents=valuein.substring(decipos+3)
      if (cents.length=="")
         cents="00" 
      var formatStr="$"+dollars+"."+cents
      return formatStr
    }

Ben Horne
-------------------------
I don't want to sound like I haven't made any mistakes. I'm confident I have.

Most likely using FireFox and concocting my next Macromedia Flash project
Snibworks Forums Moderator

Welcome to the New Age
__________________
Ben Horne
-------------------------
I don\'t want to sound like I haven\'t made any mistakes. I\'m confident I have.

Most likely using FireFox and concocting my next Macromedia Flash project
Snibworks Forums Moderator

Welcome to the New Age
 
Old November 30th, 2004, 08:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you post some more of the code, including the function calls and some sample data ?





Similar Threads
Thread Thread Starter Forum Replies Last Post
'Timeout expired' error due to query or busyServer cJeffreywang ASP.NET 2.0 Basics 6 May 2nd, 2008 01:31 PM
Text Box too wide due to value? Ron Howerton HTML Code Clinic 0 May 7th, 2007 01:34 PM
Unable to open ebook due to DRM Error abel714 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 September 2nd, 2006 07:13 PM
excel freezes due to Application.DisplayAlerts paul20091968 Excel VBA 1 July 22nd, 2006 02:41 AM
Mixing Data access logic and business logic polrtex BOOK: Professional Jakarta Struts 0 December 15th, 2003 07:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.