View Full Version : Problem with calculation - Giving the wrong answer

HiEverybody

07-11-2004, 02:43 PM

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

Willy Duitt

07-11-2004, 03:03 PM

<script>

var Text1 = 160

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

</script>

HiEverybody

07-11-2004, 03:26 PM

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

dumpfi

07-11-2004, 03:35 PM

Try this:

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

Willy Duitt

07-11-2004, 03:35 PM

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>

HiEverybody

07-11-2004, 03:54 PM

Sending out a thanx to Dumpfi and Willy.

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

Cheers

Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.