Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Problem with calculation - Giving the wrong answer

1. ## 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

• <script>
var Text1 = 160
alert(Math.round(((Text1 * 0.15)+ Text1)/12))
</script>

• 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

• 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

• 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>

• 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
•