Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem with calculation - Giving the wrong answer

    This is my calculation

    Math.round((Text1 * 0.15)+ Text1) /12)

    Text1 is the variable

    When I enter a value for Text 1 for example 160

    the answer must be 15.

    But I get an answer of 2013
    The rounding of the integer part works fine.
    When I do the calculation on the calculator I get the correct answer
    Can somebody show me what I am doing wrong

    Your Help will be much appreciated!!!!!

    Thanx

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <script>
    var Text1 = 160
    alert(Math.round(((Text1 * 0.15)+ Text1)/12))
    </script>

  • #3
    New Coder
    Join Date
    Jul 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Here is the code for my calculation

    var Text1 = prompt("Enter the amount you want to borrow and click OK", "");
    Form.output.value = ("On an amount of R" + Text1 + " with a fixed interest rate of 15%. The repayment will be R" + Math.round(((Text1 * 0.15)+ Text1) /12) +" over a period of 12 months.");

    As you can see that I have to enter an amount and it does a calculation and shows the answer in a textbox.

    It shows the correct answer if I do it your way but My way won't work it gives me an answer of 2013 instead of 15.

    Please have a look at it again and thankx for your help

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Try this:
    Code:
    var Text1 = new Number(window.prompt("Enter the amount you want to borrow and click OK", ""));
    document.Form.output.value = ("On an amount of R" + Text1 + " with a fixed interest rate of 15%. The repayment will be R" + Math.round(((Text1 * 0.15)+ Text1) /12) + " over a period of 12 months.");
    dumpfi

  • #5
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Coming from the prompt your value is a string not a number.
    You need to convert it (Text1) to a number using parseInt() or the shortcut of multplying by 1.....

    <script>
    var Text1 = prompt("Enter the amount you want to borrow and click OK", "");
    alert(Math.round(((Text1 * 0.15)+ Text1*1)/12))
    </script>

  • #6
    New Coder
    Join Date
    Jul 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Sending out a thanx to Dumpfi and Willy.

    Thank You both for your help I appreciate it!!!!!!

    Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •